<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li class="active"><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. 数据库能够做什么">1. 数据库能够做什么</a></li><li><a href="#t12. 数据库的基本概念">2. 数据库的基本概念</a><ul><li><a href="#t22.1 实体">2.1 实体</a></li><li><a href="#t32.2 数据库(DB)">2.2 数据库(DB)</a></li><li><a href="#t42.3 数据库管理系统(DBMS)">2.3 数据库管理系统(DBMS)</a></li><li><a href="#t52.4  SQL">2.4  SQL</a></li><li><a href="#t62.5  SQL规范">2.5  SQL规范</a></li></ul></li><li><a href="#t73. 数据表">3. 数据表</a></li><li><a href="#t84.MYSQL简介">4.MYSQL简介</a><ul><li><a href="#t94.1 MYSQL特点">4.1 MYSQL特点</a></li><li><a href="#t104.2 MYSQL安装">4.2 MYSQL安装</a></li><li><a href="#t114.3 MYSQL配置">4.3 MYSQL配置</a></li><li><a href="#t124.4  MYSQL启动和停止">4.4  MYSQL启动和停止</a></li><li><a href="#t134.5 通过命令行连接MYSQL">4.5 通过命令行连接MYSQL</a></li><li><a href="#t144.6 切换数据库">4.6 切换数据库</a></li><li><a href="#t154.7 显示有哪些表">4.7 显示有哪些表</a></li><li><a href="#t164.8 显示当前数据库">4.8 显示当前数据库</a></li><li><a href="#t174.9 查询表结构">4.9 查询表结构</a></li></ul></li><li><a href="#t185. 创建表">5. 创建表</a></li><li><a href="#t196. 数据完整性">6. 数据完整性</a><ul><li><a href="#t206.1 域完整性">6.1 域完整性</a></li><li><a href="#t216.2 默认值">6.2 默认值</a></li><li><a href="#t226.3 非空约束">6.3 非空约束</a></li></ul></li><li><a href="#t237.实体完整性">7.实体完整性</a><ul><li><a href="#t247.1 主键约束">7.1 主键约束</a></li><li><a href="#t257.1.1  主键">7.1.1  主键</a></li><li><a href="#t267.1.2  外键">7.1.2  外键</a></li><li><a href="#t277.1.3  唯一约束">7.1.3  唯一约束</a></li><li><a href="#t287.1.4  标识列">7.1.4  标识列</a></li><li><a href="#t297.1.5  外键约束">7.1.5  外键约束</a></li></ul></li><li><a href="#t309. SQL">9. SQL</a><ul><li><a href="#t319.1 SQL是什么">9.1 SQL是什么</a></li><li><a href="#t329.2 为什么要用SQL">9.2 为什么要用SQL</a></li><li><a href="#t339.3 SQL组成">9.3 SQL组成</a><ul><li><a href="#t349.3.1 DDL（data definition language）是数据定义语言">9.3.1 DDL（data definition language）是数据定义语言</a></li><li><a href="#t359.3.2  DML（data manipulation language）是数据操纵语言">9.3.2  DML（data manipulation language）是数据操纵语言</a></li><li><a href="#t369.3.3   DCL（DataControlLanguage）是数据库控制语言">9.3.3   DCL（DataControlLanguage）是数据库控制语言</a></li></ul></li><li><a href="#t379.4  SQL运算符">9.4  SQL运算符</a></li><li><a href="#t389.4.1 算术运算符">9.4.1 算术运算符</a></li><li><a href="#t399.4.2  逻辑运算符">9.4.2  逻辑运算符</a></li><li><a href="#t409.4.3   比较运算符">9.4.3   比较运算符</a></li></ul></li><li><a href="#t419.5 查询窗口">9.5 查询窗口</a></li><li><a href="#t429.6 数据操作语言">9.6 数据操作语言</a><ul><li><a href="#t439.6.1  插入数据行">9.6.1  插入数据行</a></li><li><a href="#t449.6.1.1 语法">9.6.1.1 语法</a></li><li><a href="#t459.6.1.2 向学生表插入一条记录, 姓名张三,身份证号123456,年龄30,城市北京">9.6.1.2 向学生表插入一条记录, 姓名张三,身份证号123456,年龄30,城市北京</a></li><li><a href="#t469.6.1.3 注意事项">9.6.1.3 注意事项</a></li><li><a href="#t479.6.2  更新数据行">9.6.2  更新数据行</a></li><li><a href="#t489.6.2.1 语法">9.6.2.1 语法</a></li><li><a href="#t499.6.2.2 更新ID等于7的学生年龄改为40，城市改为上海">9.6.2.2 更新ID等于7的学生年龄改为40，城市改为上海</a></li><li><a href="#t509.6.2.3 注意">9.6.2.3 注意</a></li><li><a href="#t519.6.3   删除数据">9.6.3   删除数据</a></li><li><a href="#t529.6.2.1 语法">9.6.2.1 语法</a></li><li><a href="#t539.6.2.2 删除ID=7的学生记录">9.6.2.2 删除ID=7的学生记录</a></li><li><a href="#t549.6.2.3 注意">9.6.2.3 注意</a></li><li><a href="#t559.6.4 TRUNCATE 截断表">9.6.4 TRUNCATE 截断表</a></li><li><a href="#t569.6.4.1 语法">9.6.4.1 语法</a><ul><li><a href="#t579.6.4.2 截断学生表">9.6.4.2 截断学生表</a></li></ul></li></ul></li><li><a href="#t589.7  数据查询">9.7  数据查询</a><ul><li><a href="#t599.7.1  查询">9.7.1  查询</a></li><li><a href="#t609.7.1.1   语法">9.7.1.1   语法</a></li><li><a href="#t619.7.1.2 查询北京的学生信息，并按ID正序排列">9.7.1.2 查询北京的学生信息，并按ID正序排列</a></li><li><a href="#t629.7.1.3  别名">9.7.1.3  别名</a></li><li><a href="#t639.7.1.4  查询空行">9.7.1.4  查询空行</a></li><li><a href="#t649.7.1.5  常量列">9.7.1.5  常量列</a></li><li><a href="#t659.7.1.6  限制返回的行数">9.7.1.6  限制返回的行数</a></li><li><a href="#t669.7.1.7  查询同学们一共来自哪些不同的城市">9.7.1.7  查询同学们一共来自哪些不同的城市</a></li><li><a href="#t679.7.1.8  在MYSQL中+号只能用作运算符">9.7.1.8  在MYSQL中+号只能用作运算符</a></li><li><a href="#t689.7.1.7  练习">9.7.1.7  练习</a><ul><li><a href="#t699.7.1.7.1  准备数据">9.7.1.7.1  准备数据</a></li><li><a href="#t709.7.1.7.2  查询山东省的同学全部信息">9.7.1.7.2  查询山东省的同学全部信息</a></li><li><a href="#t719.7.1.7.3  查询山东省的男同学的全部信息">9.7.1.7.3  查询山东省的男同学的全部信息</a></li><li><a href="#t729.7.1.7.4  查询没有填写电子邮箱的同学的姓名和身份证号">9.7.1.7.4  查询没有填写电子邮箱的同学的姓名和身份证号</a></li></ul></li><li><a href="#t739.7.1.8 排序">9.7.1.8 排序</a><ul><li><a href="#t749.7.1.8.1 把学生的分数按升序排列">9.7.1.8.1 把学生的分数按升序排列</a></li><li><a href="#t759.7.1.8.2 把学生的分数按降序排列">9.7.1.8.2 把学生的分数按降序排列</a></li><li><a href="#t769.7.1.8.3 课程编号按升序，成绩按降序">9.7.1.8.3 课程编号按升序，成绩按降序</a></li></ul></li></ul></li><li><a href="#t779.8 函数">9.8 函数</a><ul><li><a href="#t789.8.1  字符函数">9.8.1  字符函数</a><ul><li><a href="#t799.8.1.1  LENGTH">9.8.1.1  LENGTH</a></li><li><a href="#t809.8.1.2  拼接字符串 [CONCAT]">9.8.1.2  拼接字符串 [CONCAT]</a></li><li><a href="#t819.8.1.3  拼接字符串 [UPPER]">9.8.1.3  拼接字符串 [UPPER]</a></li><li><a href="#t829.8.1.4  拼接字符串 [LOWER]">9.8.1.4  拼接字符串 [LOWER]</a></li><li><a href="#t839.8.1.5  截取字符串 [SUBSTR]">9.8.1.5  截取字符串 [SUBSTR]</a></li><li><a href="#t849.8.1.6  姓名的首字符大写，其它字符小写然后用_拼接">9.8.1.6  姓名的首字符大写，其它字符小写然后用_拼接</a></li><li><a href="#t859.8.1.7  返回子串在原始字符串的起始索引">9.8.1.7  返回子串在原始字符串的起始索引</a></li><li><a href="#t869.8.1.8  去掉左右空格[TRIM]">9.8.1.8  去掉左右空格[TRIM]</a></li><li><a href="#t879.8.1.9  用空格补齐[LPAD]">9.8.1.9  用空格补齐[LPAD]</a></li><li><a href="#t889.8.1.10  替换">9.8.1.10  替换</a></li><li><a href="#t899.8.1.11  FORMAT">9.8.1.11  FORMAT</a></li><li><a href="#t909.8.1.12 LEFT RIGHT">9.8.1.12 LEFT RIGHT</a></li></ul></li><li><a href="#t919.8.2 数学函数">9.8.2 数学函数</a><ul><li><a href="#t929.8.2.1 四舍五入">9.8.2.1 四舍五入</a></li><li><a href="#t939.8.2.2 向上取整">9.8.2.2 向上取整</a></li><li><a href="#t949.8.2.3 向下取整">9.8.2.3 向下取整</a></li><li><a href="#t959.8.2.4 截断">9.8.2.4 截断</a></li><li><a href="#t969.8.2.5 取余">9.8.2.5 取余</a></li></ul></li><li><a href="#t979.8.3 日期函数">9.8.3 日期函数</a><ul><li><a href="#t989.8.3.1 返回日期时间">9.8.3.1 返回日期时间</a></li><li><a href="#t999.8.3.2 返回日期">9.8.3.2 返回日期</a></li><li><a href="#t1009.8.3.3 返回日期">9.8.3.3 返回日期</a></li><li><a href="#t1019.8.3.4 返回日期中指定的部分">9.8.3.4 返回日期中指定的部分</a></li><li><a href="#t1029.8.3.5 str_to_date">9.8.3.5 str_to_date</a></li><li><a href="#t1039.8.3.6">9.8.3.6</a></li><li><a href="#t1049.8.3.7 DATE_FORMAT">9.8.3.7 DATE_FORMAT</a></li><li><a href="#t1059.8.3.8 DATE_ADD">9.8.3.8 DATE_ADD</a></li><li><a href="#t1069.8.3.9 DATEDIFF">9.8.3.9 DATEDIFF</a></li></ul></li><li><a href="#t1079.8.4 其它函数">9.8.4 其它函数</a></li><li><a href="#t1089.9 流程控制函数">9.9 流程控制函数</a><ul><li><a href="#t1099.9.1 IF">9.9.1 IF</a></li><li><a href="#t1109.9.2 CASE函数">9.9.2 CASE函数</a></li></ul></li><li><a href="#t1119.10 练习">9.10 练习</a><ul><li><a href="#t1129.10.1. 把学生表中的邮箱地址全部由小写改为大写">9.10.1. 把学生表中的邮箱地址全部由小写改为大写</a></li><li><a href="#t1139.10.2. 字段level中的数据是  1-1、1-2、2-3之类的，现在要求先按前半部分升序排列，再按后半部分降序排列">9.10.2. 字段level中的数据是  1-1、1-2、2-3之类的，现在要求先按前半部分升序排列，再按后半部分降序排列</a></li><li><a href="#t1149.10.3. 查询年龄超过18岁的男学生">9.10.3. 查询年龄超过18岁的男学生</a></li><li><a href="#t1159.10.4. 查询出生月份是9月的山东省同学">9.10.4. 查询出生月份是9月的山东省同学</a></li><li><a href="#t1169.10.5. 查询生日是今天的学生姓名">9.10.5. 查询生日是今天的学生姓名</a></li><li><a href="#t1179.10.6. 查询ID为3的同学邮箱域名">9.10.6. 查询ID为3的同学邮箱域名</a></li></ul></li><li><a href="#t1189.11 自定义函数">9.11 自定义函数</a><ul><li><a href="#t1199.11.1 语法">9.11.1 语法</a></li><li><a href="#t1209.11.2 实例">9.11.2 实例</a></li></ul></li><li><a href="#t1219.12 模糊查询">9.12 模糊查询</a><ul><li><a href="#t1229.12.1 通配符">9.12.1 通配符</a></li><li><a href="#t1239.12.2  BETWEEN AND">9.12.2  BETWEEN AND</a></li><li><a href="#t1249.12.3  IN">9.12.3  IN</a></li><li><a href="#t1259.12.4 IS NUL">9.12.4 IS NUL</a></li></ul></li></ul></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. &#x6570;&#x636E;&#x5E93;&#x80FD;&#x591F;&#x505A;&#x4EC0;&#x4E48;">1. &#x6570;&#x636E;&#x5E93;&#x80FD;&#x591F;&#x505A;&#x4EC0;&#x4E48; <a href="#t01. &#x6570;&#x636E;&#x5E93;&#x80FD;&#x591F;&#x505A;&#x4EC0;&#x4E48;"> # </a></h2>
<ul>
<li>&#x5B58;&#x50A8;&#x5927;&#x91CF;&#x6570;&#x636E;&#xFF0C;&#x65B9;&#x4FBF;&#x68C0;&#x7D22;&#x548C;&#x8BBF;&#x95EE;</li>
<li>&#x4FDD;&#x6301;&#x6570;&#x636E;&#x4FE1;&#x606F;&#x7684;&#x4E00;&#x81F4;&#x3001;&#x5B8C;&#x6574;</li>
<li>&#x5171;&#x4EAB;&#x548C;&#x5B89;&#x5168;</li>
<li>&#x901A;&#x8FC7;&#x7EC4;&#x5408;&#x5206;&#x6790;&#xFF0C;&#x4EA7;&#x751F;&#x65B0;&#x7684;&#x6709;&#x7528;&#x4FE1;&#x606F;</li>
</ul>
<h2 id="t12. &#x6570;&#x636E;&#x5E93;&#x7684;&#x57FA;&#x672C;&#x6982;&#x5FF5;">2. &#x6570;&#x636E;&#x5E93;&#x7684;&#x57FA;&#x672C;&#x6982;&#x5FF5; <a href="#t12. &#x6570;&#x636E;&#x5E93;&#x7684;&#x57FA;&#x672C;&#x6982;&#x5FF5;"> # </a></h2>
<h3 id="t22.1 &#x5B9E;&#x4F53;">2.1 &#x5B9E;&#x4F53; <a href="#t22.1 &#x5B9E;&#x4F53;"> # </a></h3>
<p>&#x53EA;&#x8981;&#x662F;&#x5728;&#x5BA2;&#x89C2;&#x4E16;&#x754C;&#x5B58;&#x5728;&#x7684;&#x3001;&#x53EF;&#x4EE5;&#x88AB;&#x63CF;&#x8FF0;&#x51FA;&#x6765;&#x7684;&#x90FD;&#x662F;&#x5B9E;&#x4F53;</p>
<h3 id="t32.2 &#x6570;&#x636E;&#x5E93;(DB)">2.2 &#x6570;&#x636E;&#x5E93;(DB) <a href="#t32.2 &#x6570;&#x636E;&#x5E93;(DB)"> # </a></h3>
<ul>
<li>&#x6570;&#x636E;&#x5E93;&#x5C31;&#x662F;&#x6570;&#x636E;&#x7684;&#x4ED3;&#x5E93;&#xFF0C;&#x53EF;&#x4EE5;&#x5B58;&#x653E;&#x7ED3;&#x6784;&#x5316;&#x7684;&#x6570;&#x636E;</li>
</ul>
<h3 id="t42.3 &#x6570;&#x636E;&#x5E93;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;(DBMS)">2.3 &#x6570;&#x636E;&#x5E93;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;(DBMS) <a href="#t42.3 &#x6570;&#x636E;&#x5E93;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;(DBMS)"> # </a></h3>
<p>&#x662F;&#x4E00;&#x79CD;&#x7CFB;&#x7EDF;&#x8F6F;&#x4EF6;&#xFF0C;&#x63D0;&#x4F9B;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;&#x7684;&#x73AF;&#x5883;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6570;&#x636E;&#x5E93;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#x5BF9;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x63D2;&#x5165;&#x3001;&#x4FEE;&#x6539;&#x3001;&#x5220;&#x9664;&#x548C;&#x67E5;&#x8BE2;&#x7B49;&#x64CD;&#x4F5C;&#x3002;</p>
<h3 id="t52.4  SQL">2.4  SQL <a href="#t52.4  SQL"> # </a></h3>
<p>&#x7ED3;&#x6784;&#x5316;&#x67E5;&#x8BE2;&#x8BED;&#x8A00; &#x4E13;&#x95E8;&#x7528;&#x6765;&#x548C;&#x6570;&#x636E;&#x5E93;&#x8FDB;&#x884C;&#x4EA4;&#x6D41;&#x7684;&#x8BED;&#x8A00;,&#x51E0;&#x4E4E;&#x6240;&#x6709;&#x7684;DBMS&#x90FD;&#x652F;&#x6301;SQL</p>
<p><img src="http://img.zhufengpeixun.cn/dbmspng.png" alt="dbms"></p>
<h3 id="t62.5  SQL&#x89C4;&#x8303;">2.5  SQL&#x89C4;&#x8303; <a href="#t62.5  SQL&#x89C4;&#x8303;"> # </a></h3>
<ol>
<li>SQL&#x8BED;&#x53E5;&#x4E0D;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#xFF0C;&#x5EFA;&#x8BAE;SQL&#x5173;&#x952E;&#x5B57;&#x5927;&#x5199;&#xFF0C;&#x8868;&#x540D;&#x548C;&#x5217;&#x8868;&#x5C0F;&#x5199;</li>
<li>&#x547D;&#x4EE4;&#x7528;&#x5206;&#x53F7;&#x7ED3;&#x5C3E;</li>
<li>&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x7F29;&#x8FDB;&#x548C;&#x6362;&#x884C;&#xFF0C;&#x4E00;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x5173;&#x952E;&#x5B57;&#x653E;&#x5728;&#x4E00;&#x884C;</li>
<li>&#x53EF;&#x4EE5;&#x5199;&#x5355;&#x884C;&#x548C;&#x591A;&#x884C;&#x6CE8;&#x91CA; , #&#x548C;--&#x662F;&#x5355;&#x884C;&#x6CE8;&#x91CA;&#xFF0C;/***/&#x591A;&#x884C;&#x6CE8;&#x91CA;</li>
</ol>
<h2 id="t73. &#x6570;&#x636E;&#x8868;">3. &#x6570;&#x636E;&#x8868; <a href="#t73. &#x6570;&#x636E;&#x8868;"> # </a></h2>
<ul>
<li>&#x8868;&#x662F;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x5305;&#x542B;&#x6240;&#x6709;&#x6570;&#x636E;&#x7684;&#x6570;&#x636E;&#x5E93;&#x5BF9;&#x8C61;&#xFF0C;&#x4E5F;&#x662F;&#x5176;&#x5B83;&#x5BF9;&#x8C61;&#x7684;&#x57FA;&#x7840;&#x3002;</li>
<li>&#x8868;&#x5B9A;&#x4E49;&#x662F;&#x4E00;&#x4E2A;&#x5217;&#x7684;&#x96C6;&#x5408;&#xFF0C;&#x6570;&#x636E;&#x5728;&#x8868;&#x4E2D;&#x662F;&#x6309;&#x884C;&#x548C;&#x5217;&#x7684;&#x683C;&#x5F0F;&#x7EC4;&#x7EC7;&#x7684;&#xFF0C;&#x7528;&#x6765;&#x5B58;&#x653E;&#x6570;&#x636E;</li>
<li>&#x884C;&#x4E5F;&#x79F0;&#x4E3A;&#x8BB0;&#x5F55;&#x7528;&#x6765;&#x5B58;&#x653E;&#x4E00;&#x4E2A;&#x4E2A;&#x5B9E;&#x4F53;&#xFF0C;&#x5217;&#x79F0;&#x4E3A;&#x5B57;&#x6BB5;&#x7528;&#x6765;&#x63CF;&#x8FF0;&#x5B9E;&#x4F53;&#x7684;&#x67D0;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;
&#x5B66;&#x751F;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF; </li>
</ul>
<p><img src="http://img.zhufengpeixun.cn/table.png" alt="table"></p>
<h2 id="t84.MYSQL&#x7B80;&#x4ECB;">4.MYSQL&#x7B80;&#x4ECB; <a href="#t84.MYSQL&#x7B80;&#x4ECB;"> # </a></h2>
<h3 id="t94.1 MYSQL&#x7279;&#x70B9;">4.1 MYSQL&#x7279;&#x70B9; <a href="#t94.1 MYSQL&#x7279;&#x70B9;"> # </a></h3>
<ul>
<li>&#x5F00;&#x6E90;&#x514D;&#x8D39;</li>
<li>&#x6027;&#x80FD;&#x9AD8;</li>
<li>&#x5B89;&#x88C5;&#x4F7F;&#x7528;&#x90FD;&#x7B80;&#x5355;</li>
</ul>
<h3 id="t104.2 MYSQL&#x5B89;&#x88C5;">4.2 MYSQL&#x5B89;&#x88C5; <a href="#t104.2 MYSQL&#x5B89;&#x88C5;"> # </a></h3>
<ul>
<li><a href="https://dev.mysql.com/downloads/mysql/5.5.html">mysql&#x4E0B;&#x8F7D;</a></li>
<li>&#x5B89;&#x88C5;MYSQL</li>
</ul>
<h3 id="t114.3 MYSQL&#x914D;&#x7F6E;">4.3 MYSQL&#x914D;&#x7F6E; <a href="#t114.3 MYSQL&#x914D;&#x7F6E;"> # </a></h3>
<p>C:\Program Files\MySQL\MySQL Server 5.5\my.ini</p>
<ul>
<li>port &#x7AEF;&#x53E3;&#x53F7;</li>
<li>basedir &#x5B89;&#x88C5;&#x76EE;&#x5F55;</li>
<li>datadir &#x6570;&#x636E;&#x5B58;&#x653E;&#x8BBF;&#x76EE;&#x5F55;</li>
<li>charcter-set-server &#x5B57;&#x7B26;&#x96C6;</li>
<li>default-storage-engine &#x5B58;&#x50A8;&#x5F15;&#x64CE;</li>
<li>sql-mode &#x8BED;&#x6CD5;&#x6A21;&#x5F0F;</li>
<li>max-connections &#x6700;&#x5927;&#x8FDE;&#x63A5;&#x6570;</li>
</ul>
<h3 id="t124.4  MYSQL&#x542F;&#x52A8;&#x548C;&#x505C;&#x6B62;">4.4  MYSQL&#x542F;&#x52A8;&#x548C;&#x505C;&#x6B62; <a href="#t124.4  MYSQL&#x542F;&#x52A8;&#x548C;&#x505C;&#x6B62;"> # </a></h3>
<pre><code class="lang-js">net start MySQL
net stop MySQL
</code></pre>
<h3 id="t134.5 &#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x884C;&#x8FDE;&#x63A5;MYSQL">4.5 &#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x884C;&#x8FDE;&#x63A5;MYSQL <a href="#t134.5 &#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x884C;&#x8FDE;&#x63A5;MYSQL"> # </a></h3>
<pre><code class="lang-js">mysql -h <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> -P <span class="hljs-number">3306</span> -uroot -p123456
exit
</code></pre>
<h3 id="t144.6 &#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;">4.6 &#x5207;&#x6362;&#x6570;&#x636E;&#x5E93; <a href="#t144.6 &#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;"> # </a></h3>
<pre><code class="lang-js">use test;
</code></pre>
<h3 id="t154.7 &#x663E;&#x793A;&#x6709;&#x54EA;&#x4E9B;&#x8868;">4.7 &#x663E;&#x793A;&#x6709;&#x54EA;&#x4E9B;&#x8868; <a href="#t154.7 &#x663E;&#x793A;&#x6709;&#x54EA;&#x4E9B;&#x8868;"> # </a></h3>
<pre><code class="lang-js">show tables;
show tables <span class="hljs-keyword">from</span> mysql;
</code></pre>
<h3 id="t164.8 &#x663E;&#x793A;&#x5F53;&#x524D;&#x6570;&#x636E;&#x5E93;">4.8 &#x663E;&#x793A;&#x5F53;&#x524D;&#x6570;&#x636E;&#x5E93; <a href="#t164.8 &#x663E;&#x793A;&#x5F53;&#x524D;&#x6570;&#x636E;&#x5E93;"> # </a></h3>
<pre><code class="lang-js">select database();
</code></pre>
<h3 id="t174.9 &#x67E5;&#x8BE2;&#x8868;&#x7ED3;&#x6784;">4.9 &#x67E5;&#x8BE2;&#x8868;&#x7ED3;&#x6784; <a href="#t174.9 &#x67E5;&#x8BE2;&#x8868;&#x7ED3;&#x6784;"> # </a></h3>
<pre><code class="lang-js">DESC user;
</code></pre>
<h2 id="t185. &#x521B;&#x5EFA;&#x8868;">5. &#x521B;&#x5EFA;&#x8868; <a href="#t185. &#x521B;&#x5EFA;&#x8868;"> # </a></h2>
<p><img src="http://img.zhufengpeixun.cn/students.png" alt="student">
<img src="http://img.zhufengpeixun.cn/course.png" alt="course">
<img src="http://img.zhufengpeixun.cn/score.png" alt="score"></p>
<h2 id="t196. &#x6570;&#x636E;&#x5B8C;&#x6574;&#x6027;">6. &#x6570;&#x636E;&#x5B8C;&#x6574;&#x6027; <a href="#t196. &#x6570;&#x636E;&#x5B8C;&#x6574;&#x6027;"> # </a></h2>
<ul>
<li>&#x4E3A;&#x4E86;&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x5B8C;&#x6574;&#x6027;&#xFF0C;&#x9700;&#x8981;&#x68C0;&#x9A8C;&#x6570;&#x636E;&#x5E93;&#x8868;&#x4E2D;&#x7684;&#x6BCF;&#x884C;&#x548C;&#x6BCF;&#x5217;&#x6570;&#x636E;&#x662F;&#x5426;&#x7B26;&#x5408;&#x8981;&#x6C42;</li>
<li>&#x5728;&#x521B;&#x5EFA;&#x8868;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5E94;&#x8BE5;&#x4FDD;&#x8BC1;&#x4EE5;&#x540E;&#x7684;&#x6570;&#x636E;&#x8F93;&#x5165;&#x662F;&#x6B63;&#x786E;&#x7684;&#xFF0C;&#x9519;&#x8BEF;&#x7684;&#x6570;&#x636E;&#x4E0D;&#x5141;&#x8BB8;&#x8F93;&#x5165;</li>
</ul>
<h3 id="t206.1 &#x57DF;&#x5B8C;&#x6574;&#x6027;">6.1 &#x57DF;&#x5B8C;&#x6574;&#x6027; <a href="#t206.1 &#x57DF;&#x5B8C;&#x6574;&#x6027;"> # </a></h3>
<p>&#x4E0D;&#x540C;&#x7684;&#x5B57;&#x6BB5;&#x9700;&#x8981;&#x8BBE;&#x7F6E;&#x4E3A;&#x5404;&#x79CD;&#x5408;&#x9002;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x6BD4;&#x5982;&#x5E74;&#x9F84;&#x5C31;&#x662F;&#x6574;&#x6570;&#x7C7B;&#x578B;</p>
<p><img src="http://img.zhufengpeixun.cn/datatype.jpg" alt="datatype"></p>
<h3 id="t216.2 &#x9ED8;&#x8BA4;&#x503C;">6.2 &#x9ED8;&#x8BA4;&#x503C; <a href="#t216.2 &#x9ED8;&#x8BA4;&#x503C;"> # </a></h3>
<p>&#x9ED8;&#x8BA4;&#x503C;&#x662F;&#x6307;&#x5982;&#x679C;&#x7528;&#x6237;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#x503C;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x4F1A;&#x8BB0;&#x5F55;&#x7684;&#x6B64;&#x5B57;&#x6BB5;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x9884;&#x5148;&#x8BBE;&#x5B9A;&#x7684;&#x503C;</p>
<blockquote>
<p>&#x53EF;&#x4EE5;&#x628A;&#x5C45;&#x4F4F;&#x5730;&#x9ED8;&#x8BA4;&#x503C;&#x8BBE;&#x7F6E;&#x4E3A;&#x5317;&#x4EAC;</p>
</blockquote>
<h3 id="t226.3 &#x975E;&#x7A7A;&#x7EA6;&#x675F;">6.3 &#x975E;&#x7A7A;&#x7EA6;&#x675F; <a href="#t226.3 &#x975E;&#x7A7A;&#x7EA6;&#x675F;"> # </a></h3>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x67D0;&#x4E2A;&#x5B57;&#x6BB5;&#x4E0D;&#x80FD;&#x4E0D;&#x8F93;&#x5165;&#xFF0C;&#x5FC5;&#x987B;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x975E;&#x7A7A;&#x7684;&#x503C;</p>
<blockquote>
<p>&#x59D3;&#x540D;&#x5B57;&#x6BB5;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;</p>
</blockquote>
<h2 id="t237.&#x5B9E;&#x4F53;&#x5B8C;&#x6574;&#x6027;">7.&#x5B9E;&#x4F53;&#x5B8C;&#x6574;&#x6027; <a href="#t237.&#x5B9E;&#x4F53;&#x5B8C;&#x6574;&#x6027;"> # </a></h2>
<h3 id="t247.1 &#x4E3B;&#x952E;&#x7EA6;&#x675F;">7.1 &#x4E3B;&#x952E;&#x7EA6;&#x675F; <a href="#t247.1 &#x4E3B;&#x952E;&#x7EA6;&#x675F;"> # </a></h3>
<h3 id="t257.1.1  &#x4E3B;&#x952E;">7.1.1  &#x4E3B;&#x952E; <a href="#t257.1.1  &#x4E3B;&#x952E;"> # </a></h3>
<p>&#x8868;&#x4E2D;&#x4E00;&#x5217;&#x6216;&#x8005;&#x51E0;&#x5217;&#x7EC4;&#x5408;&#x7684;&#x503C;&#x80FD;&#x7528;&#x6765;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x8868;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x884C;&#xFF0C;&#x8FD9;&#x6837;&#x7684;&#x5217;&#x6216;&#x8005;&#x5217;&#x7EC4;&#x5408;&#x79F0;&#x4E3A;&#x8868;&#x7684;&#x4E3B;&#x952E;&#xFF0C;&#x4E3B;&#x952E;&#x8868;&#x7684;&#x6570;&#x636E;&#x4E0D;&#x540C;&#x91CD;&#x590D;&#x3002;</p>
<blockquote>
<p>&#x5982;&#x679C;&#x4E24;&#x5217;&#x6216;&#x8005;&#x591A;&#x5217;&#x7EC4;&#x5408;&#x8D77;&#x6765;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x8868;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x884C;&#xFF0C;&#x5219;&#x8BE5;&#x4E3B;&#x952E;&#x53C8;&#x79F0;&#x4E3A;&quot;&#x7EC4;&#x5408;&#x952E;&quot;</p>
</blockquote>
<p><strong>&#x4E3B;&#x952E;&#x7684;&#x9009;&#x62E9;&#x6807;&#x51C6;</strong></p>
<ol>
<li>&#x6700;&#x5C11;&#x6027; &#x5C3D;&#x91CF;&#x9009;&#x62E9;&#x5355;&#x4E2A;&#x952E;&#x4F5C;&#x4E3A;&#x4E3B;&#x952E; </li>
<li>&#x7A33;&#x5B9A;&#x6027; &#xFF0C;&#x7531;&#x4E8E;&#x4E3B;&#x952E;&#x662F;&#x7528;&#x6765;&#x5728;&#x4E24;&#x4E2A;&#x8868;&#x95F4;&#x5EFA;&#x7ACB;&#x8054;&#x63A5;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x80FD;&#x7ECF;&#x5E38;&#x66F4;&#x65B0;&#xFF0C;&#x6700;&#x597D;&#x5C31;&#x4E0D;&#x66F4;&#x65B0;</li>
</ol>
<h3 id="t267.1.2  &#x5916;&#x952E;">7.1.2  &#x5916;&#x952E; <a href="#t267.1.2  &#x5916;&#x952E;"> # </a></h3>
<p> &#x6210;&#x7EE9;&#x8868;&#x4E2D;&#x7684;&#x5B66;&#x751F;ID&#x5E94;&#x8BE5;&#x5728;&#x5B66;&#x751F;&#x8868;&#x4E2D;&#x662F;&#x5B58;&#x5728;&#x7684;
 &#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x8BA9;&#x6210;&#x7EE9;&#x8868;&#x4E2D;&#x7684;ID&#x53EA;&#x80FD;&#x5F15;&#x7528;&#x5B66;&#x751F;&#x8868;&#x4E2D;&#x7684;ID&#xFF0C;&#x5B83;&#x4EEC;&#x7684;&#x503C;&#x5E94;&#x8BE5;&#x662F;&#x4E00;&#x4E00;&#x5BF9;&#x5E94;&#x7684;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x6210;&#x7EE9;&#x8868;&#x4E2D;&#x7684;ID&#x662F;&#x6210;&#x7EE9;&#x8868;&#x4E2D;&#x7684;&#x5916;&#x952E;&#xFF0C;&#x5BF9;&#x5E94;&#x5B66;&#x751F;&#x8868;&#x7684;&#x4E3B;&#x952E; &#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x53EF;&#x4EE5;&#x4FDD;&#x8BC1;&#x6570;&#x636E;&#x7684;&#x5F15;&#x7528;&#x5B8C;&#x6574;&#x6027;</p>
<h3 id="t277.1.3  &#x552F;&#x4E00;&#x7EA6;&#x675F;">7.1.3  &#x552F;&#x4E00;&#x7EA6;&#x675F; <a href="#t277.1.3  &#x552F;&#x4E00;&#x7EA6;&#x675F;"> # </a></h3>
<p>&#x552F;&#x4E00;&#x7EA6;&#x675F;&#x662F;&#x6307;&#x67D0;&#x4E2A;&#x5B57;&#x6BB5;&#x503C;&#x662F;&#x552F;&#x4E00;&#x7684;&#xFF0C;&#x5728;&#x6240;&#x6709;&#x7684;&#x8BB0;&#x5F55;&#x4E2D;&#x4E0D;&#x80FD;&#x6709;&#x91CD;&#x590D;&#x7684;&#x503C;.</p>
<blockquote>
<p>&#x5B66;&#x751F;&#x7684;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x4E3A;&#x552F;&#x4E00;&#x7EA6;&#x675F;</p>
</blockquote>
<h3 id="t287.1.4  &#x6807;&#x8BC6;&#x5217;">7.1.4  &#x6807;&#x8BC6;&#x5217; <a href="#t287.1.4  &#x6807;&#x8BC6;&#x5217;"> # </a></h3>
<ul>
<li>&#x5F53;&#x8868;&#x4E2D;&#x6CA1;&#x6709;&#x5408;&#x9002;&#x7684;&#x5217;&#x4F5C;&#x4E3A;&#x4E3B;&#x952E;&#x65F6;&#x53EF;&#x4EE5;&#x8003;&#x8651;&#x589E;&#x52A0;&#x6807;&#x8BC6;&#x5217;&#xFF0C;&#x6807;&#x8BC6;&#x5217;&#x662F;&#x4E00;&#x4E2A;&#x65E0;&#x5B9E;&#x9645;&#x4E1A;&#x52A1;&#x542B;&#x4E49;&#x7684;&#x5217;&#xFF0C;&#x4EC5;&#x4EC5;&#x7528;&#x6765;&#x533A;&#x5206;&#x6BCF;&#x6761;&#x8BB0;&#x5F55;&#x3002;</li>
<li>&#x6807;&#x8BC6;&#x5217;&#x7684;&#x503C;&#x662F;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x7684;&#xFF0C;&#x4E0D;&#x80FD;&#x5728;&#x8BE5;&#x5217;&#x4E0A;&#x8F93;&#x5165;&#x6570;&#x636E;<blockquote>
<p>&#x601D;&#x8003;: &#x5982;&#x679C;&#x6807;&#x8BC6;&#x5217;id&#x7684;&#x521D;&#x59CB;&#x503C;&#x4E3A;1&#xFF0C;&#x589E;&#x957F;&#x91CF;&#x4E3A;3&#xFF0C;&#x5219;&#x8F93;&#x5165;3&#x884C;&#x6570;&#x636E;&#x4EE5;&#x540E;&#xFF0C;&#x518D;&#x5220;&#x9664;1&#x884C;&#xFF0C;&#x4E0B;&#x6B21;&#x518D;&#x8F93;&#x5165;&#x6570;&#x636E;&#x884C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6807;&#x8BC6;&#x503C;&#x81EA;&#x52A8;&#x63D2;&#x5165;&#x7684;&#x503C;&#x662F;&#x591A;&#x5C11;?</p>
</blockquote>
</li>
</ul>
<h3 id="t297.1.5  &#x5916;&#x952E;&#x7EA6;&#x675F;">7.1.5  &#x5916;&#x952E;&#x7EA6;&#x675F; <a href="#t297.1.5  &#x5916;&#x952E;&#x7EA6;&#x675F;"> # </a></h3>
<p>&#x4E00;&#x4E2A;&#x8868;&#x7684;&#x5916;&#x952E;&#x5FC5;&#x987B;&#x5F15;&#x7528;&#x53E6;&#x4E00;&#x4E2A;&#x8868;&#x7684;&#x4E3B;&#x952E;,&#x6BD4;&#x5982;&#x6210;&#x7EE9;&#x8868;&#x4E2D;&#x7684;&#x5B66;&#x751F;ID&#x4F1A;&#x5F15;&#x7528;&#x5B66;&#x751F;&#x8868;&#x7684;&#x4E3B;&#x952E;&#xFF0C;&#x8BFE;&#x7A0B;ID&#x4F1A;&#x5F15;&#x7528;&#x6210;&#x7EE9;&#x8868;&#x7684;&#x4E3B;&#x952E;</p>
<ul>
<li>&#x4E3B;&#x8868;&#x6CA1;&#x6709;&#x8BB0;&#x5F55;&#xFF0C;&#x5B50;&#x8868;&#x4E2D;&#x4E0D;&#x80FD;&#x6DFB;&#x52A0;&#x76F8;&#x5E94;&#x7684;&#x8BB0;&#x5F55;</li>
<li><p>&#x4FEE;&#x6539;&#x548C;&#x5220;&#x9664;&#x4E3B;&#x8868;&#x8BB0;&#x5F55;&#x4E0D;&#x80FD;&#x8BA9;&#x5B50;&#x8868;&#x8BB0;&#x5F55;&#x5B64;&#x7ACB;&#xFF0C;&#x5FC5;&#x987B;&#x76F8;&#x5E94;&#x4FEE;&#x6539;&#x548C;&#x5220;&#x9664;</p>
</li>
<li><p>&#x6570;&#x636E;&#x64CD;&#x4F5C;
8.1 &#x521B;&#x5EFA;&#x5B66;&#x751F;&#x8868;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span> (
<span class="hljs-string">`id`</span>  <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> PRIMARY <span class="hljs-keyword">KEY</span> AUTO_INCREMENT   ,
<span class="hljs-string">`name`</span>  <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> ,
<span class="hljs-string">`age`</span>  <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span> ,
<span class="hljs-string">`city`</span>  <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;&#x5317;&#x4EAC;&apos;</span> ,
)
</code></pre>
</li>
</ul>
<p>8.2 &#x589E;&#x52A0;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;&#x5B57;&#x6BB5;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">ADD</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-string">`idcard`</span>  <span class="hljs-built_in">varchar</span>(<span class="hljs-number">15</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">AFTER</span> <span class="hljs-string">`city`</span>; <span class="hljs-comment">--&#x589E;&#x52A0;&#x8EAB;&#x4EFD;&#x8BC1;&#x5B57;&#x6BB5;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">MODIFY</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-string">`idcard`</span>  <span class="hljs-built_in">varchar</span>(<span class="hljs-number">18</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">AFTER</span> <span class="hljs-string">`name`</span>; <span class="hljs-comment">--&#x4FEE;&#x6539;&#x8EAB;&#x4EFD;&#x8BC1;&#x5B57;&#x6BB5;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-string">`idcard`</span>; <span class="hljs-comment">--&#x5220;&#x9664;&#x8EAB;&#x4EFD;&#x8BC1;&#x5B57;&#x6BB5;</span>
</code></pre>
<p>8.3 &#x6DFB;&#x52A0;&#x7EA6;&#x675F;</p>
<pre><code class="lang-sql"><span class="hljs-comment">-- &#x4E3B;&#x952E;&#x7EA6;&#x675F;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">ADD</span> PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`id`</span>);
<span class="hljs-comment">-- &#x552F;&#x4E00;&#x7EA6;&#x675F;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">ADD</span> <span class="hljs-keyword">UNIQUE</span> <span class="hljs-keyword">INDEX</span> <span class="hljs-string">`uq_idcard`</span> (<span class="hljs-string">`idcard`</span>) ;
<span class="hljs-comment">-- &#x9ED8;&#x8BA4;&#x7EA6;&#x675F;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">MODIFY</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-string">`city`</span>  <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>)  <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;&#x5317;&#x4EAC;&apos;</span> <span class="hljs-keyword">AFTER</span> <span class="hljs-string">`age`</span>;
<span class="hljs-comment">-- &#x5916;&#x952E;&#x7EA6;&#x675F;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">ADD</span> <span class="hljs-keyword">CONSTRAINT</span> <span class="hljs-string">`fk_stuid`</span> <span class="hljs-keyword">FOREIGN</span> <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`student_id`</span>) <span class="hljs-keyword">REFERENCES</span> <span class="hljs-string">`student`</span> (<span class="hljs-string">`id`</span>);
<span class="hljs-comment">-- &#x5220;&#x9664;&#x7EA6;&#x675F;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">DROP</span> <span class="hljs-keyword">FOREIGN</span> <span class="hljs-keyword">KEY</span> <span class="hljs-string">`fk_stuid`</span>;
</code></pre>
<p>8.4 &#x51C6;&#x5907;&#x6570;&#x636E; </p>
<p><img src="http://img.zhufengpeixun.cn/relations.png" alt="relations"></p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span> (
  <span class="hljs-string">`id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT,
  <span class="hljs-string">`name`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>,
  <span class="hljs-string">`idcard`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">18</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>,
  <span class="hljs-string">`age`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>,
  <span class="hljs-string">`city`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;&apos;</span>,
  PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`id`</span>)
);

<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`course`</span> (
  <span class="hljs-string">`id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT,
  <span class="hljs-string">`name`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>,
  PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`id`</span>)
);

<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`score`</span> (
  <span class="hljs-string">`student_id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span>,
  <span class="hljs-string">`course_id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span>,
  <span class="hljs-string">`grade`</span> <span class="hljs-built_in">float</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>,
  PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`student_id`</span>,<span class="hljs-string">`course_id`</span>),
  <span class="hljs-keyword">KEY</span> <span class="hljs-string">`fk_courseid`</span> (<span class="hljs-string">`course_id`</span>),
  <span class="hljs-keyword">CONSTRAINT</span> <span class="hljs-string">`fk_courseid`</span> <span class="hljs-keyword">FOREIGN</span> <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`course_id`</span>) <span class="hljs-keyword">REFERENCES</span> <span class="hljs-string">`course`</span> (<span class="hljs-string">`id`</span>),
  <span class="hljs-keyword">CONSTRAINT</span> <span class="hljs-string">`fk_stuid`</span> <span class="hljs-keyword">FOREIGN</span> <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`student_id`</span>) <span class="hljs-keyword">REFERENCES</span> <span class="hljs-string">`student`</span> (<span class="hljs-string">`id`</span>)
) <span class="hljs-keyword">ENGINE</span>=<span class="hljs-keyword">InnoDB</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARSET</span>=utf8;

</code></pre>
<h2 id="t309. SQL">9. SQL <a href="#t309. SQL"> # </a></h2>
<h3 id="t319.1 SQL&#x662F;&#x4EC0;&#x4E48;">9.1 SQL&#x662F;&#x4EC0;&#x4E48; <a href="#t319.1 SQL&#x662F;&#x4EC0;&#x4E48;"> # </a></h3>
<p>Structured Query Language&#xFF1A;&#x7ED3;&#x6784;&#x5316;&#x67E5;&#x8BE2;&#x8BED;&#x8A00;</p>
<h3 id="t329.2 &#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x7528;SQL">9.2 &#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x7528;SQL <a href="#t329.2 &#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x7528;SQL"> # </a></h3>
<ol>
<li>&#x4F7F;&#x7528;&#x754C;&#x9762;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;&#x4E0D;&#x65B9;&#x4FBF;</li>
<li>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x53BB;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;</li>
</ol>
<h3 id="t339.3 SQL&#x7EC4;&#x6210;">9.3 SQL&#x7EC4;&#x6210; <a href="#t339.3 SQL&#x7EC4;&#x6210;"> # </a></h3>
<h4 id="t349.3.1 DDL&#xFF08;data definition language&#xFF09;&#x662F;&#x6570;&#x636E;&#x5B9A;&#x4E49;&#x8BED;&#x8A00;">9.3.1 DDL&#xFF08;data definition language&#xFF09;&#x662F;&#x6570;&#x636E;&#x5B9A;&#x4E49;&#x8BED;&#x8A00; <a href="#t349.3.1 DDL&#xFF08;data definition language&#xFF09;&#x662F;&#x6570;&#x636E;&#x5B9A;&#x4E49;&#x8BED;&#x8A00;"> # </a></h4>
<p>&#x4E3B;&#x8981;&#x7684;&#x547D;&#x4EE4;&#x6709;<code>CREATE</code>&#x3001;<code>ALTER</code>&#x3001;<code>DROP</code>&#x7B49;&#xFF0C;<strong>DDL</strong>&#x4E3B;&#x8981;&#x662F;&#x7528;&#x5728;&#x5B9A;&#x4E49;&#x6216;&#x6539;&#x53D8;&#x8868;&#xFF08;TABLE&#xFF09;&#x7684;&#x7ED3;&#x6784;&#xFF0C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x8868;&#x4E4B;&#x95F4;&#x7684;&#x94FE;&#x63A5;&#x548C;&#x7EA6;&#x675F;&#x7B49;&#x521D;&#x59CB;&#x5316;&#x5DE5;&#x4F5C;&#x4E0A;&#xFF0C;&#x4ED6;&#x4EEC;&#x5927;&#x591A;&#x5728;&#x5EFA;&#x7ACB;&#x8868;&#x65F6;&#x4F7F;&#x7528;</p>
<h4 id="t359.3.2  DML&#xFF08;data manipulation language&#xFF09;&#x662F;&#x6570;&#x636E;&#x64CD;&#x7EB5;&#x8BED;&#x8A00;">9.3.2  DML&#xFF08;data manipulation language&#xFF09;&#x662F;&#x6570;&#x636E;&#x64CD;&#x7EB5;&#x8BED;&#x8A00; <a href="#t359.3.2  DML&#xFF08;data manipulation language&#xFF09;&#x662F;&#x6570;&#x636E;&#x64CD;&#x7EB5;&#x8BED;&#x8A00;"> # </a></h4>
<p>&#x5B83;&#x4EEC;&#x662F;<code>SELECT</code>&#x3001;<code>UPDATE&#x3001;</code>INSERT<code>&#x3001;</code>DELETE`&#xFF0C;&#x5C31;&#x8C61;&#x5B83;&#x7684;&#x540D;&#x5B57;&#x4E00;&#x6837;&#xFF0C;&#x8FD9;4&#x6761;&#x547D;&#x4EE4;&#x662F;&#x7528;&#x6765;&#x5BF9;&#x6570;&#x636E;&#x5E93;&#x91CC;&#x7684;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#x7684;&#x8BED;&#x8A00;</p>
<h4 id="t369.3.3   DCL&#xFF08;DataControlLanguage&#xFF09;&#x662F;&#x6570;&#x636E;&#x5E93;&#x63A7;&#x5236;&#x8BED;&#x8A00;">9.3.3   DCL&#xFF08;DataControlLanguage&#xFF09;&#x662F;&#x6570;&#x636E;&#x5E93;&#x63A7;&#x5236;&#x8BED;&#x8A00; <a href="#t369.3.3   DCL&#xFF08;DataControlLanguage&#xFF09;&#x662F;&#x6570;&#x636E;&#x5E93;&#x63A7;&#x5236;&#x8BED;&#x8A00;"> # </a></h4>
<p>&#x662F;&#x7528;&#x6765;&#x8BBE;&#x7F6E;&#x6216;&#x66F4;&#x6539;&#x6570;&#x636E;&#x5E93;&#x7528;&#x6237;&#x6216;&#x89D2;&#x8272;&#x6743;&#x9650;&#x7684;&#x8BED;&#x53E5;&#xFF0C;&#x5305;&#x62EC;&#xFF08;<code>grant</code>,<code>revoke</code>&#x7B49;&#xFF09;&#x8BED;&#x53E5;</p>
<h3 id="t379.4  SQL&#x8FD0;&#x7B97;&#x7B26;">9.4  SQL&#x8FD0;&#x7B97;&#x7B26; <a href="#t379.4  SQL&#x8FD0;&#x7B97;&#x7B26;"> # </a></h3>
<p>&#x662F;&#x4E00;&#x79CD;&#x7B26;&#x53F7;&#xFF0C;&#x5B83;&#x662F;&#x7528;&#x6765;&#x8FDB;&#x884C;&#x5217;&#x95F4;&#x6216;&#x8005;&#x53D8;&#x91CF;&#x4E4B;&#x95F4;&#x7684;&#x6BD4;&#x8F83;&#x548C;&#x6570;&#x5B66;&#x8FD0;&#x7B97;&#x7684;</p>
<h3 id="t389.4.1 &#x7B97;&#x672F;&#x8FD0;&#x7B97;&#x7B26;">9.4.1 &#x7B97;&#x672F;&#x8FD0;&#x7B97;&#x7B26; <a href="#t389.4.1 &#x7B97;&#x672F;&#x8FD0;&#x7B97;&#x7B26;"> # </a></h3>
<table>
<thead>
<tr>
<th style="text-align:left">&#x8FD0;&#x7B97;&#x7B26;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">+</td>
<td style="text-align:left">&#x52A0;&#x8FD0;&#x7B97;&#xFF0C;&#x6C42;&#x4E24;&#x4E2A;&#x6570;&#x6216;&#x8868;&#x8FBE;&#x5F0F;&#x76F8;&#x52A0;&#x7684;&#x548C;&#xFF0C;&#x5982;1+1</td>
</tr>
<tr>
<td style="text-align:left">-</td>
<td style="text-align:left">&#x51CF;&#x5C11;&#x51CF;&#x8FD0;&#x7B97;&#xFF0C;&#x6C42;&#x4E24;&#x4E2A;&#x6570;&#x6216;&#x8868;&#x8FBE;&#x5F0F;&#x76F8;&#x51CF;&#x7684;&#x5DEE;&#xFF0C;&#x5982;4-1</td>
</tr>
<tr>
<td style="text-align:left">*</td>
<td style="text-align:left">&#x4E58;&#x8FD0;&#x7B97;&#xFF0C;&#x6C42;&#x4E24;&#x4E2A;&#x6570;&#x6216;&#x8868;&#x8FBE;&#x5F0F;&#x76F8;&#x4E58;&#x7684;&#x79EF;&#xFF0C;&#x5982;2*2</td>
</tr>
<tr>
<td style="text-align:left">/</td>
<td style="text-align:left">&#x9664;&#x8FD0;&#x7B97;&#xFF0C;&#x6C42;&#x4E24;&#x4E2A;&#x6570;&#x6216;&#x8868;&#x8FBE;&#x5F0F;&#x76F8;&#x9664;&#x7684;&#x5546;&#xFF0C;&#x5982;6/4&#x7684;&#x503C;&#x4E3A;1</td>
</tr>
<tr>
<td style="text-align:left">%</td>
<td style="text-align:left">&#x53D6;&#x6A21;&#x8FD0;&#x7B97;&#xFF0C;&#x6C42;&#x4E24;&#x4E2A;&#x6570;&#x6216;&#x8868;&#x8FBE;&#x5F0F;&#x76F8;&#x9664;&#x7684;&#x4F59;&#x6570;&#xFF0C;&#x5982;&#xFF1A;6%4&#x7684;&#x503C;&#x4E3A;2</td>
</tr>
</tbody>
</table>
<ul>
<li>&#x67E5;&#x8BE2;&#x59D3;&#x540D;&#x5168;&#x79F0;</li>
</ul>
<h3 id="t399.4.2  &#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26;">9.4.2  &#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26; <a href="#t399.4.2  &#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26;"> # </a></h3>
<table>
<thead>
<tr>
<th style="text-align:left">&#x8FD0;&#x7B97;&#x7B26;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">AND</td>
<td style="text-align:left">&#x5F53;&#x4E14;&#x4EC5;&#x5F53;&#x4E24;&#x4E2A;&#x5E03;&#x5C14;&#x8868;&#x8FBE;&#x5F0F;&#x90FD;&#x4E3A;true&#x65F6;&#xFF0C;&#x8FD4;&#x56DE;TRUE</td>
</tr>
<tr>
<td style="text-align:left">OR</td>
<td style="text-align:left">&#x5F53;&#x4E14;&#x4EC5;&#x5F53;&#x4E24;&#x4E2A;&#x5E03;&#x5C14;&#x8868;&#x8FBE;&#x5F0F;&#x90FD;&#x4E3A;false&#xFF0C;&#x8FD4;&#x56DE;FALSE</td>
</tr>
<tr>
<td style="text-align:left">NOT</td>
<td style="text-align:left">&#x5E03;&#x5C14;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x503C;&#x53D6;&#x53CD;</td>
</tr>
</tbody>
</table>
<h3 id="t409.4.3   &#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;">9.4.3   &#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26; <a href="#t409.4.3   &#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;"> # </a></h3>
<table>
<thead>
<tr>
<th style="text-align:left">&#x8FD0;&#x7B97;&#x7B26;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">=</td>
<td style="text-align:left">&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&gt;</td>
<td style="text-align:left">&#x5927;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&lt;</td>
<td style="text-align:left">&#x5C0F;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&lt;&gt;</td>
<td style="text-align:left">&#x4E0D;&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&gt;=</td>
<td style="text-align:left">&#x5927;&#x4E8E;&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&lt;=</td>
<td style="text-align:left">&#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">!=</td>
<td style="text-align:left">&#x4E0D;&#x7B49;&#x4E8E;</td>
</tr>
</tbody>
</table>
<h2 id="t419.5 &#x67E5;&#x8BE2;&#x7A97;&#x53E3;">9.5 &#x67E5;&#x8BE2;&#x7A97;&#x53E3; <a href="#t419.5 &#x67E5;&#x8BE2;&#x7A97;&#x53E3;"> # </a></h2>
<p><img src="http://img.zhufengpeixun.cn/query.png" alt="query"></p>
<h2 id="t429.6 &#x6570;&#x636E;&#x64CD;&#x4F5C;&#x8BED;&#x8A00;">9.6 &#x6570;&#x636E;&#x64CD;&#x4F5C;&#x8BED;&#x8A00; <a href="#t429.6 &#x6570;&#x636E;&#x64CD;&#x4F5C;&#x8BED;&#x8A00;"> # </a></h2>
<h3 id="t439.6.1  &#x63D2;&#x5165;&#x6570;&#x636E;&#x884C;">9.6.1  &#x63D2;&#x5165;&#x6570;&#x636E;&#x884C; <a href="#t439.6.1  &#x63D2;&#x5165;&#x6570;&#x636E;&#x884C;"> # </a></h3>
<h3 id="t449.6.1.1 &#x8BED;&#x6CD5;">9.6.1.1 &#x8BED;&#x6CD5; <a href="#t449.6.1.1 &#x8BED;&#x6CD5;"> # </a></h3>
<pre><code class="lang-sql"> <span class="hljs-keyword">INSERT</span>  [<span class="hljs-keyword">INTO</span>]  &#x8868;&#x540D;  [(&#x5217;&#x540D;)] <span class="hljs-keyword">VALUES</span>  (&#x503C;&#x5217;&#x8868;)
</code></pre>
<h3 id="t459.6.1.2 &#x5411;&#x5B66;&#x751F;&#x8868;&#x63D2;&#x5165;&#x4E00;&#x6761;&#x8BB0;&#x5F55;, &#x59D3;&#x540D;&#x5F20;&#x4E09;,&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;123456,&#x5E74;&#x9F84;30,&#x57CE;&#x5E02;&#x5317;&#x4EAC;">9.6.1.2 &#x5411;&#x5B66;&#x751F;&#x8868;&#x63D2;&#x5165;&#x4E00;&#x6761;&#x8BB0;&#x5F55;, &#x59D3;&#x540D;&#x5F20;&#x4E09;,&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;123456,&#x5E74;&#x9F84;30,&#x57CE;&#x5E02;&#x5317;&#x4EAC; <a href="#t459.6.1.2 &#x5411;&#x5B66;&#x751F;&#x8868;&#x63D2;&#x5165;&#x4E00;&#x6761;&#x8BB0;&#x5F55;, &#x59D3;&#x540D;&#x5F20;&#x4E09;,&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;123456,&#x5E74;&#x9F84;30,&#x57CE;&#x5E02;&#x5317;&#x4EAC;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> [school].[student]
(<span class="hljs-keyword">name</span>,idcard,age,city)
<span class="hljs-keyword">VALUES</span>
(<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>,<span class="hljs-string">&apos;123456&apos;</span>,<span class="hljs-number">30</span>,<span class="hljs-string">&apos;&#x5317;&#x4EAC;&apos;</span>)
</code></pre>
<h3 id="t469.6.1.3 &#x6CE8;&#x610F;&#x4E8B;&#x9879;">9.6.1.3 &#x6CE8;&#x610F;&#x4E8B;&#x9879; <a href="#t469.6.1.3 &#x6CE8;&#x610F;&#x4E8B;&#x9879;"> # </a></h3>
<ul>
<li>&#x6BCF;&#x6B21;&#x63D2;&#x5165;&#x4E00;&#x884C;&#x6570;&#x636E;&#xFF0C;&#x4E0D;&#x80FD;&#x53EA;&#x63D2;&#x5165;&#x4E00;&#x90E8;&#x5206;&#x6570;&#x636E;&#xFF0C;&#x63D2;&#x5165;&#x7684;&#x6570;&#x636E;&#x662F;&#x5426;&#x6709;&#x6548;&#x5C06;&#x6309;&#x7167;&#x6574;&#x884C;&#x7684;&#x5B8C;&#x6574;&#x6027;&#x8981;&#x6C42;&#x6765;&#x68C0;&#x9A8C;</li>
<li>&#x6BCF;&#x4E2A;&#x6570;&#x636E;&#x503C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3001;&#x7CBE;&#x5EA6;&#x3001;&#x4F4D;&#x6570;&#x5FC5;&#x987B;&#x4E0E;&#x8981;&#x5E94;&#x7684;&#x5217;&#x540D;&#x7CBE;&#x786E;&#x5339;&#x914D;</li>
<li>&#x4E0D;&#x80FD;&#x4E3A;&#x6807;&#x8BC6;&#x7B26;&#x6307;&#x5B9A;&#x503C;</li>
<li>&#x5982;&#x679C;&#x67D0;&#x5B57;&#x6BB5;&#x8BBE;&#x7F6E;&#x4E3A;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;&#xFF0C;&#x5219;&#x5FC5;&#x987B;&#x63D2;&#x5165;&#x6570;&#x636E;</li>
<li>&#x63D2;&#x5165;&#x6570;&#x636E;&#x65F6;&#x8FD8;&#x8981;&#x7B26;&#x5408;&#x68C0;&#x67E5;&#x6027;&#x7EA6;&#x675F;&#x7684;&#x8981;&#x6C42;</li>
<li>&#x6709;&#x7F3A;&#x7701;&#x503C;&#x7684;&#x5217;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;DEFAULT&#x5173;&#x952E;&#x5B57;&#x6765;&#x4EE3;&#x66FF;&#x63D2;&#x5165;&#x5B9E;&#x9645;&#x7684;&#x503C;</li>
</ul>
<h3 id="t479.6.2  &#x66F4;&#x65B0;&#x6570;&#x636E;&#x884C;">9.6.2  &#x66F4;&#x65B0;&#x6570;&#x636E;&#x884C; <a href="#t479.6.2  &#x66F4;&#x65B0;&#x6570;&#x636E;&#x884C;"> # </a></h3>
<h3 id="t489.6.2.1 &#x8BED;&#x6CD5;">9.6.2.1 &#x8BED;&#x6CD5; <a href="#t489.6.2.1 &#x8BED;&#x6CD5;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">UPDATE</span> &#x8868;&#x540D; <span class="hljs-keyword">SET</span> &#x5217;&#x540D; = &#x66F4;&#x65B0;&#x503C; [<span class="hljs-keyword">WHERE</span> &#x66F4;&#x65B0;&#x6761;&#x4EF6;]
</code></pre>
<h3 id="t499.6.2.2 &#x66F4;&#x65B0;ID&#x7B49;&#x4E8E;7&#x7684;&#x5B66;&#x751F;&#x5E74;&#x9F84;&#x6539;&#x4E3A;40&#xFF0C;&#x57CE;&#x5E02;&#x6539;&#x4E3A;&#x4E0A;&#x6D77;">9.6.2.2 &#x66F4;&#x65B0;ID&#x7B49;&#x4E8E;7&#x7684;&#x5B66;&#x751F;&#x5E74;&#x9F84;&#x6539;&#x4E3A;40&#xFF0C;&#x57CE;&#x5E02;&#x6539;&#x4E3A;&#x4E0A;&#x6D77; <a href="#t499.6.2.2 &#x66F4;&#x65B0;ID&#x7B49;&#x4E8E;7&#x7684;&#x5B66;&#x751F;&#x5E74;&#x9F84;&#x6539;&#x4E3A;40&#xFF0C;&#x57CE;&#x5E02;&#x6539;&#x4E3A;&#x4E0A;&#x6D77;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">UPDATE</span> [school].[student]
   <span class="hljs-keyword">SET</span> age = <span class="hljs-number">40</span>,city = <span class="hljs-string">&apos;&#x4E0A;&#x6D77;&apos;</span>
<span class="hljs-keyword">WHERE</span> <span class="hljs-keyword">id</span>=<span class="hljs-number">7</span>
</code></pre>
<h3 id="t509.6.2.3 &#x6CE8;&#x610F;">9.6.2.3 &#x6CE8;&#x610F; <a href="#t509.6.2.3 &#x6CE8;&#x610F;"> # </a></h3>
<ul>
<li>&#x591A;&#x5217;&#x65F6;&#x7528;&#x9017;&#x53F7;&#x9694;&#x5F00;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x52A0;&#x66F4;&#x65B0;&#x6761;&#x4EF6;&#x4EE5;&#x514D;&#x9519;&#x8BEF;&#x66F4;&#x65B0;</li>
<li>&#x591A;&#x4E2A;&#x8054;&#x5408;&#x6761;&#x4EF6;&#x4F7F;&#x7528; AND <code>id=7 and idcard=&apos;410787&apos;</code></li>
<li>&#x5224;&#x65AD;&#x67D0;&#x5B57;&#x6BB5;&#x662F;&#x5426;&#x4E3A;&#x7A7A; <code>email is null or email = &apos;&apos;</code></li>
</ul>
<h3 id="t519.6.3   &#x5220;&#x9664;&#x6570;&#x636E;">9.6.3   &#x5220;&#x9664;&#x6570;&#x636E; <a href="#t519.6.3   &#x5220;&#x9664;&#x6570;&#x636E;"> # </a></h3>
<h3 id="t529.6.2.1 &#x8BED;&#x6CD5;">9.6.2.1 &#x8BED;&#x6CD5; <a href="#t529.6.2.1 &#x8BED;&#x6CD5;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">DELETE</span> [<span class="hljs-keyword">FROM</span>]  &#x8868;&#x540D; [<span class="hljs-keyword">WHERE</span> &lt;&#x5220;&#x9664;&#x6761;&#x4EF6;&gt;]
</code></pre>
<h3 id="t539.6.2.2 &#x5220;&#x9664;ID=7&#x7684;&#x5B66;&#x751F;&#x8BB0;&#x5F55;">9.6.2.2 &#x5220;&#x9664;ID=7&#x7684;&#x5B66;&#x751F;&#x8BB0;&#x5F55; <a href="#t539.6.2.2 &#x5220;&#x9664;ID=7&#x7684;&#x5B66;&#x751F;&#x8BB0;&#x5F55;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">DELETE</span> <span class="hljs-keyword">FROM</span> [school].[student] <span class="hljs-keyword">WHERE</span> <span class="hljs-keyword">id</span>=<span class="hljs-number">7</span>
</code></pre>
<h3 id="t549.6.2.3 &#x6CE8;&#x610F;">9.6.2.3 &#x6CE8;&#x610F; <a href="#t549.6.2.3 &#x6CE8;&#x610F;"> # </a></h3>
<ul>
<li>Delete&#x8BED;&#x53E5;&#x662F;&#x5BF9;&#x6574;&#x884C;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x5217;&#x540D;</li>
<li>&#x5982;&#x679C;&#x8981;&#x5220;&#x9664;&#x4E3B;&#x8868;&#x6570;&#x636E;&#xFF0C;&#x5219;&#x8981;&#x5148;&#x5220;&#x9664;&#x5B50;&#x8868;&#x8BB0;&#x5F55;</li>
</ul>
<h3 id="t559.6.4 TRUNCATE &#x622A;&#x65AD;&#x8868;">9.6.4 TRUNCATE &#x622A;&#x65AD;&#x8868; <a href="#t559.6.4 TRUNCATE &#x622A;&#x65AD;&#x8868;"> # </a></h3>
<p>&#x622A;&#x65AD;&#x6574;&#x4E2A;&#x8868;&#x4E2D;&#x7684;&#x6570;&#x636E;</p>
<h3 id="t569.6.4.1 &#x8BED;&#x6CD5;">9.6.4.1 &#x8BED;&#x6CD5; <a href="#t569.6.4.1 &#x8BED;&#x6CD5;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">TRUNCATE</span>  <span class="hljs-keyword">TABLE</span>  &#x8868;&#x540D;
</code></pre>
<h4 id="t579.6.4.2 &#x622A;&#x65AD;&#x5B66;&#x751F;&#x8868;">9.6.4.2 &#x622A;&#x65AD;&#x5B66;&#x751F;&#x8868; <a href="#t579.6.4.2 &#x622A;&#x65AD;&#x5B66;&#x751F;&#x8868;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">TRUNCATE</span> <span class="hljs-keyword">TABLE</span> student
</code></pre>
<blockquote>
<p> &#x6570;&#x636E;&#x5168;&#x90E8;&#x6E05;&#x7A7A;,&#x4F46;&#x8868;&#x7ED3;&#x6784;&#x3001;&#x5217;&#x3001;&#x7EA6;&#x675F;&#x7B49;&#x4E0D;&#x88AB;&#x6539;&#x52A8;
 &#x4E0D;&#x80FD;&#x7528;&#x4E8E;&#x6709;&#x5916;&#x952E;&#x7EA6;&#x675F;&#x5F15;&#x7528;&#x7684;&#x8868;
 &#x6807;&#x8BC6;&#x5217;&#x91CD;&#x65B0;&#x5F00;&#x59CB;&#x7F16;&#x53F7;
 &#x56E0;&#x4E3A;&#x8981;&#x5220;&#x9664;&#x7684;&#x6570;&#x636E;&#x4E0D;&#x4F1A;&#x5199;&#x5165;&#x65E5;&#x5FD7;&#xFF0C;&#x6570;&#x636E;&#x4E5F;&#x4E0D;&#x80FD;&#x6062;&#x590D;&#xFF0C;&#x6240;&#x4EE5;&#x5DE5;&#x4F5C;&#x4E2D;&#x8BF7;&#x5C3D;&#x91CF;&#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x6B64;&#x547D;&#x4EE4;</p>
</blockquote>
<h2 id="t589.7  &#x6570;&#x636E;&#x67E5;&#x8BE2;">9.7  &#x6570;&#x636E;&#x67E5;&#x8BE2; <a href="#t589.7  &#x6570;&#x636E;&#x67E5;&#x8BE2;"> # </a></h2>
<ul>
<li>&#x67E5;&#x8BE2;&#x5C31;&#x662F;&#x4ECE;&#x5BA2;&#x6237;&#x7AEF; &#x53D1;&#x51FA;&#x67E5;&#x8BE2;&#x8BF7;&#x6C42;&#x6570;&#x636E;&#x5E93;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5E76;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x8FD4;&#x56DE;&#x67E5;&#x8BE2;&#x7ED3;&#x679C;&#x7684;&#x8FC7;&#x7A0B;</li>
<li>&#x6BCF;&#x6B21;&#x6267;&#x884C;&#x67E5;&#x8BE2;&#x53EA;&#x662F;&#x4ECE;&#x6570;&#x636E;&#x8868;&#x4E2D;&#x63D0;&#x53D6;&#x6570;&#x636E;&#xFF0C;&#x5E76;&#x6309;&#x8868;&#x7684;&#x65B9;&#x5F0F;&#x5448;&#x73B0;&#x51FA;&#x6765;</li>
<li>&#x67E5;&#x8BE2;&#x4EA7;&#x751F;&#x7684;&#x662F;&#x865A;&#x62DF;&#x8868;,&#x5E76;&#x4E0D;&#x4F1A;&#x4FDD;&#x5B58;&#x8D77;&#x6765;</li>
</ul>
<h3 id="t599.7.1  &#x67E5;&#x8BE2;">9.7.1  &#x67E5;&#x8BE2; <a href="#t599.7.1  &#x67E5;&#x8BE2;"> # </a></h3>
<h3 id="t609.7.1.1   &#x8BED;&#x6CD5;">9.7.1.1   &#x8BED;&#x6CD5; <a href="#t609.7.1.1   &#x8BED;&#x6CD5;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span>    &lt;&#x5217;&#x540D;&gt; 
<span class="hljs-keyword">FROM</span>      &lt;&#x8868;&#x540D;&gt; 
[<span class="hljs-keyword">WHERE</span>    &lt;&#x67E5;&#x8BE2;&#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&gt;] 
[<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> &lt;&#x6392;&#x5E8F;&#x7684;&#x5217;&#x540D;&gt;[<span class="hljs-keyword">ASC</span>&#x6216;<span class="hljs-keyword">DESC</span>]]
</code></pre>
<h3 id="t619.7.1.2 &#x67E5;&#x8BE2;&#x5317;&#x4EAC;&#x7684;&#x5B66;&#x751F;&#x4FE1;&#x606F;&#xFF0C;&#x5E76;&#x6309;ID&#x6B63;&#x5E8F;&#x6392;&#x5217;">9.7.1.2 &#x67E5;&#x8BE2;&#x5317;&#x4EAC;&#x7684;&#x5B66;&#x751F;&#x4FE1;&#x606F;&#xFF0C;&#x5E76;&#x6309;ID&#x6B63;&#x5E8F;&#x6392;&#x5217; <a href="#t619.7.1.2 &#x67E5;&#x8BE2;&#x5317;&#x4EAC;&#x7684;&#x5B66;&#x751F;&#x4FE1;&#x606F;&#xFF0C;&#x5E76;&#x6309;ID&#x6B63;&#x5E8F;&#x6392;&#x5217;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">id</span>,<span class="hljs-keyword">name</span>,idcard,age,city
<span class="hljs-keyword">FROM</span> student
<span class="hljs-keyword">WHERE</span> home= <span class="hljs-string">&apos;&#x5317;&#x4EAC;&apos;</span>
<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> <span class="hljs-keyword">id</span> <span class="hljs-keyword">asc</span>
</code></pre>
<p><img src="http://img.zhufengpeixun.cn/selectquery.png" alt="selectquery"></p>
<h3 id="t629.7.1.3  &#x522B;&#x540D;">9.7.1.3  &#x522B;&#x540D; <a href="#t629.7.1.3  &#x522B;&#x540D;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">id</span>,<span class="hljs-keyword">name</span>,idcard,age,city <span class="hljs-keyword">AS</span> home
<span class="hljs-keyword">FROM</span> student
<span class="hljs-keyword">WHERE</span> city= <span class="hljs-string">&apos;&#x5C71;&#x4E1C;&apos;</span>
<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> <span class="hljs-keyword">id</span> <span class="hljs-keyword">asc</span>
</code></pre>
<h3 id="t639.7.1.4  &#x67E5;&#x8BE2;&#x7A7A;&#x884C;">9.7.1.4  &#x67E5;&#x8BE2;&#x7A7A;&#x884C; <a href="#t639.7.1.4  &#x67E5;&#x8BE2;&#x7A7A;&#x884C;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">id</span>,<span class="hljs-keyword">name</span>,age,city
<span class="hljs-keyword">FROM</span> student
<span class="hljs-keyword">WHERE</span> city <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">or</span> city =<span class="hljs-string">&apos;&apos;</span>
</code></pre>
<h3 id="t649.7.1.5  &#x5E38;&#x91CF;&#x5217;">9.7.1.5  &#x5E38;&#x91CF;&#x5217; <a href="#t649.7.1.5  &#x5E38;&#x91CF;&#x5217;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">id</span>,<span class="hljs-keyword">name</span>,age,city,<span class="hljs-string">&apos;&#x4E2D;&#x56FD;&apos;</span> <span class="hljs-keyword">as</span> country
<span class="hljs-keyword">FROM</span> student
</code></pre>
<h3 id="t659.7.1.6  &#x9650;&#x5236;&#x8FD4;&#x56DE;&#x7684;&#x884C;&#x6570;">9.7.1.6  &#x9650;&#x5236;&#x8FD4;&#x56DE;&#x7684;&#x884C;&#x6570; <a href="#t659.7.1.6  &#x9650;&#x5236;&#x8FD4;&#x56DE;&#x7684;&#x884C;&#x6570;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">id</span>,<span class="hljs-keyword">name</span>,age,city,<span class="hljs-string">&apos;&#x4E2D;&#x56FD;&apos;</span> <span class="hljs-keyword">as</span> country
<span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">limit</span> <span class="hljs-number">2</span>
</code></pre>
<h3 id="t669.7.1.7  &#x67E5;&#x8BE2;&#x540C;&#x5B66;&#x4EEC;&#x4E00;&#x5171;&#x6765;&#x81EA;&#x54EA;&#x4E9B;&#x4E0D;&#x540C;&#x7684;&#x57CE;&#x5E02;">9.7.1.7  &#x67E5;&#x8BE2;&#x540C;&#x5B66;&#x4EEC;&#x4E00;&#x5171;&#x6765;&#x81EA;&#x54EA;&#x4E9B;&#x4E0D;&#x540C;&#x7684;&#x57CE;&#x5E02; <a href="#t669.7.1.7  &#x67E5;&#x8BE2;&#x540C;&#x5B66;&#x4EEC;&#x4E00;&#x5171;&#x6765;&#x81EA;&#x54EA;&#x4E9B;&#x4E0D;&#x540C;&#x7684;&#x57CE;&#x5E02;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">id</span>,<span class="hljs-keyword">name</span>,age,<span class="hljs-keyword">DISTINCT</span> city,<span class="hljs-string">&apos;&#x4E2D;&#x56FD;&apos;</span> <span class="hljs-keyword">as</span> country
<span class="hljs-keyword">FROM</span> student 
</code></pre>
<h3 id="t679.7.1.8  &#x5728;MYSQL&#x4E2D;+&#x53F7;&#x53EA;&#x80FD;&#x7528;&#x4F5C;&#x8FD0;&#x7B97;&#x7B26;">9.7.1.8  &#x5728;MYSQL&#x4E2D;+&#x53F7;&#x53EA;&#x80FD;&#x7528;&#x4F5C;&#x8FD0;&#x7B97;&#x7B26; <a href="#t679.7.1.8  &#x5728;MYSQL&#x4E2D;+&#x53F7;&#x53EA;&#x80FD;&#x7528;&#x4F5C;&#x8FD0;&#x7B97;&#x7B26;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-number">1</span>+<span class="hljs-number">1</span>
<span class="hljs-keyword">SELECT</span> <span class="hljs-number">1</span>+<span class="hljs-string">&apos;1&apos;</span>
<span class="hljs-keyword">SELECT</span> <span class="hljs-number">1</span>+<span class="hljs-string">&apos;zfpx&apos;</span>  
<span class="hljs-keyword">SELECT</span> <span class="hljs-number">1</span>+<span class="hljs-literal">null</span>
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">CONCAT</span>(last_name,first_name) <span class="hljs-keyword">FROM</span> <span class="hljs-keyword">user</span>;
</code></pre>
<h3 id="t689.7.1.7  &#x7EC3;&#x4E60;">9.7.1.7  &#x7EC3;&#x4E60; <a href="#t689.7.1.7  &#x7EC3;&#x4E60;"> # </a></h3>
<h4 id="t699.7.1.7.1  &#x51C6;&#x5907;&#x6570;&#x636E;">9.7.1.7.1  &#x51C6;&#x5907;&#x6570;&#x636E; <a href="#t699.7.1.7.1  &#x51C6;&#x5907;&#x6570;&#x636E;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`student`</span>
<span class="hljs-keyword">ADD</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-string">`province`</span>  <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">AFTER</span> <span class="hljs-string">`city`</span>,
<span class="hljs-keyword">ADD</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-string">`birthday`</span>  <span class="hljs-built_in">date</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">AFTER</span> <span class="hljs-string">`province`</span>,
<span class="hljs-keyword">ADD</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-string">`gender`</span>   <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">AFTER</span> <span class="hljs-string">`birthday`</span>,
<span class="hljs-keyword">ADD</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-string">`email`</span>  <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">AFTER</span> <span class="hljs-string">`gender`</span>;

</code></pre>
<p><img src="http://img.zhufengpeixun.cn/studenttable.png" alt="studenttable">
<img src="http://img.zhufengpeixun.cn/coursetable.png" alt="coursetable">
<img src="http://img.zhufengpeixun.cn/scoretable.png" alt="scoretable"></p>
<pre><code class="lang-sql"><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;&#x90ED;&#x9756;&apos;</span>, <span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;&#x6D4E;&#x5357;&apos;</span>, <span class="hljs-string">&apos;&#x5C71;&#x4E1C;&#x7701;&apos;</span>, <span class="hljs-string">&apos;1982-09-03&apos;</span>, <span class="hljs-number">1</span>, <span class="hljs-string">&apos;<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82b3c2f3f3ace1edef">[email&#160;protected]</a>&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;&#x9EC4;&#x84C9;&apos;</span>, <span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;&#x6D4E;&#x5357;&apos;</span>, <span class="hljs-string">&apos;&#x5C71;&#x4E1C;&#x7701;&apos;</span>, <span class="hljs-string">&apos;1982-09-03&apos;</span>, <span class="hljs-number">0</span>, <span class="hljs-string">&apos;<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b196b5a5a05484446">[email&#160;protected]</a>&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;&#x6768;&#x8FC7;&apos;</span>, <span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;&#x7EC8;&#x5357;&#x5C71;&apos;</span>, <span class="hljs-string">&apos;&#x9655;&#x897F;&#x7701;&apos;</span>, <span class="hljs-string">&apos;1979-09-03&apos;</span>, <span class="hljs-number">1</span>, <span class="hljs-string">&apos;<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cdfe8dbcbce3aea2a0">[email&#160;protected]</a>&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;4&apos;</span>, <span class="hljs-string">&apos;&#x5C0F;&#x9F99;&#x5973;&apos;</span>, <span class="hljs-string">&apos;4&apos;</span>, <span class="hljs-string">&apos;4&apos;</span>, <span class="hljs-string">&apos;&#x7EC8;&#x5357;&#x5C71;&apos;</span>, <span class="hljs-string">&apos;&#x9655;&#x897F;&#x7701;&apos;</span>, <span class="hljs-string">&apos;1970-09-03&apos;</span>, <span class="hljs-number">0</span>, <span class="hljs-string">&apos;<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="26126657570845494b">[email&#160;protected]</a>&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`student`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;5&apos;</span>, <span class="hljs-string">&apos;&#x6B27;&#x9633;&#x950B;&apos;</span>, <span class="hljs-string">&apos;5&apos;</span>, <span class="hljs-string">&apos;5&apos;</span>, <span class="hljs-string">&apos;&#x767D;&#x9A7C;&#x5C71;&apos;</span>, <span class="hljs-string">&apos;&#x65B0;&#x7586;&apos;</span>, <span class="hljs-string">&apos;1989-09-09&apos;</span>, <span class="hljs-number">1</span>, <span class="hljs-string">&apos;<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4f184b5b5eaa7aba9">[email&#160;protected]</a>&apos;</span>);


<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`course`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;&#x8BED;&#x6587;&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`course`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;&#x6570;&#x5B66;&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`course`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;&#x82F1;&#x8BED;&apos;</span>);

<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;100&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;90&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;70&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;100&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;90&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;80&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;100&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-string">&apos;90&apos;</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`score`</span> <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-string">&apos;80&apos;</span>);

</code></pre>
<h4 id="t709.7.1.7.2  &#x67E5;&#x8BE2;&#x5C71;&#x4E1C;&#x7701;&#x7684;&#x540C;&#x5B66;&#x5168;&#x90E8;&#x4FE1;&#x606F;">9.7.1.7.2  &#x67E5;&#x8BE2;&#x5C71;&#x4E1C;&#x7701;&#x7684;&#x540C;&#x5B66;&#x5168;&#x90E8;&#x4FE1;&#x606F; <a href="#t709.7.1.7.2  &#x67E5;&#x8BE2;&#x5C71;&#x4E1C;&#x7701;&#x7684;&#x540C;&#x5B66;&#x5168;&#x90E8;&#x4FE1;&#x606F;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> student <span class="hljs-keyword">where</span> province = <span class="hljs-string">&apos;&#x5C71;&#x4E1C;&apos;</span>;
</code></pre>
<h4 id="t719.7.1.7.3  &#x67E5;&#x8BE2;&#x5C71;&#x4E1C;&#x7701;&#x7684;&#x7537;&#x540C;&#x5B66;&#x7684;&#x5168;&#x90E8;&#x4FE1;&#x606F;">9.7.1.7.3  &#x67E5;&#x8BE2;&#x5C71;&#x4E1C;&#x7701;&#x7684;&#x7537;&#x540C;&#x5B66;&#x7684;&#x5168;&#x90E8;&#x4FE1;&#x606F; <a href="#t719.7.1.7.3  &#x67E5;&#x8BE2;&#x5C71;&#x4E1C;&#x7701;&#x7684;&#x7537;&#x540C;&#x5B66;&#x7684;&#x5168;&#x90E8;&#x4FE1;&#x606F;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> student <span class="hljs-keyword">where</span> province = <span class="hljs-string">&apos;&#x5C71;&#x4E1C;&apos;</span> <span class="hljs-keyword">and</span> gender=<span class="hljs-number">1</span>;
</code></pre>
<h4 id="t729.7.1.7.4  &#x67E5;&#x8BE2;&#x6CA1;&#x6709;&#x586B;&#x5199;&#x7535;&#x5B50;&#x90AE;&#x7BB1;&#x7684;&#x540C;&#x5B66;&#x7684;&#x59D3;&#x540D;&#x548C;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;">9.7.1.7.4  &#x67E5;&#x8BE2;&#x6CA1;&#x6709;&#x586B;&#x5199;&#x7535;&#x5B50;&#x90AE;&#x7BB1;&#x7684;&#x540C;&#x5B66;&#x7684;&#x59D3;&#x540D;&#x548C;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7; <a href="#t729.7.1.7.4  &#x67E5;&#x8BE2;&#x6CA1;&#x6709;&#x586B;&#x5199;&#x7535;&#x5B50;&#x90AE;&#x7BB1;&#x7684;&#x540C;&#x5B66;&#x7684;&#x59D3;&#x540D;&#x548C;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">name</span>,idcard <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">WHERE</span> email <span class="hljs-keyword">IS</span> <span class="hljs-literal">NULL</span>
</code></pre>
<h3 id="t739.7.1.8 &#x6392;&#x5E8F;">9.7.1.8 &#x6392;&#x5E8F; <a href="#t739.7.1.8 &#x6392;&#x5E8F;"> # </a></h3>
<h4 id="t749.7.1.8.1 &#x628A;&#x5B66;&#x751F;&#x7684;&#x5206;&#x6570;&#x6309;&#x5347;&#x5E8F;&#x6392;&#x5217;">9.7.1.8.1 &#x628A;&#x5B66;&#x751F;&#x7684;&#x5206;&#x6570;&#x6309;&#x5347;&#x5E8F;&#x6392;&#x5217; <a href="#t749.7.1.8.1 &#x628A;&#x5B66;&#x751F;&#x7684;&#x5206;&#x6570;&#x6309;&#x5347;&#x5E8F;&#x6392;&#x5217;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> score <span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> grade <span class="hljs-keyword">asc</span>;
</code></pre>
<h4 id="t759.7.1.8.2 &#x628A;&#x5B66;&#x751F;&#x7684;&#x5206;&#x6570;&#x6309;&#x964D;&#x5E8F;&#x6392;&#x5217;">9.7.1.8.2 &#x628A;&#x5B66;&#x751F;&#x7684;&#x5206;&#x6570;&#x6309;&#x964D;&#x5E8F;&#x6392;&#x5217; <a href="#t759.7.1.8.2 &#x628A;&#x5B66;&#x751F;&#x7684;&#x5206;&#x6570;&#x6309;&#x964D;&#x5E8F;&#x6392;&#x5217;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> score <span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> grade <span class="hljs-keyword">desc</span>;
</code></pre>
<h4 id="t769.7.1.8.3 &#x8BFE;&#x7A0B;&#x7F16;&#x53F7;&#x6309;&#x5347;&#x5E8F;&#xFF0C;&#x6210;&#x7EE9;&#x6309;&#x964D;&#x5E8F;">9.7.1.8.3 &#x8BFE;&#x7A0B;&#x7F16;&#x53F7;&#x6309;&#x5347;&#x5E8F;&#xFF0C;&#x6210;&#x7EE9;&#x6309;&#x964D;&#x5E8F; <a href="#t769.7.1.8.3 &#x8BFE;&#x7A0B;&#x7F16;&#x53F7;&#x6309;&#x5347;&#x5E8F;&#xFF0C;&#x6210;&#x7EE9;&#x6309;&#x964D;&#x5E8F;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> score <span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> course_id <span class="hljs-keyword">asc</span>, grade <span class="hljs-keyword">desc</span>;
</code></pre>
<h2 id="t779.8 &#x51FD;&#x6570;">9.8 &#x51FD;&#x6570; <a href="#t779.8 &#x51FD;&#x6570;"> # </a></h2>
<h3 id="t789.8.1  &#x5B57;&#x7B26;&#x51FD;&#x6570;">9.8.1  &#x5B57;&#x7B26;&#x51FD;&#x6570; <a href="#t789.8.1  &#x5B57;&#x7B26;&#x51FD;&#x6570;"> # </a></h3>
<table>
<thead>
<tr>
<th style="text-align:left">&#x51FD;&#x6570;&#x540D;&#x79F0;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">CONCAT</td>
<td style="text-align:left">&#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5;</td>
</tr>
<tr>
<td style="text-align:left">CONCAT_WS</td>
<td style="text-align:left">&#x4F7F;&#x7528;&#x6307;&#x5B9A;&#x7684;&#x5206;&#x9694;&#x7B26;&#x8FDB;&#x884C;&#x5B57;&#x7B26;&#x8FDE;&#x63A5;</td>
</tr>
<tr>
<td style="text-align:left">FORMAT</td>
<td style="text-align:left">&#x6570;&#x5B57;&#x683C;&#x5F0F;&#x5316;</td>
</tr>
<tr>
<td style="text-align:left">LOWER</td>
<td style="text-align:left">&#x8F6C;&#x5C0F;&#x5199;&#x5B57;&#x6BCD;</td>
</tr>
<tr>
<td style="text-align:left">UPPER</td>
<td style="text-align:left">&#x8F6C;&#x5927;&#x5199;&#x5B57;&#x6BCD;</td>
</tr>
<tr>
<td style="text-align:left">LEFT</td>
<td style="text-align:left">&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;s&#x5F00;&#x59CB;&#x7684;&#x6700;&#x5DE6;&#x8FB9;n&#x4E2A;&#x5B57;&#x7B26;</td>
</tr>
<tr>
<td style="text-align:left">RIGHT</td>
<td style="text-align:left">&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;s&#x5F00;&#x59CB;&#x7684;&#x6700;&#x5DE6;&#x8FB9;n&#x4E2A;&#x5B57;&#x7B26;</td>
</tr>
</tbody>
</table>
<h4 id="t799.8.1.1  LENGTH">9.8.1.1  LENGTH <a href="#t799.8.1.1  LENGTH"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">LENGTH</span>(<span class="hljs-string">&apos;zfpx&apos;</span>);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">LENGTH</span>(<span class="hljs-string">&apos;&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;&apos;</span>);
<span class="hljs-keyword">SHOW</span> <span class="hljs-keyword">VARIABLES</span> <span class="hljs-keyword">like</span> <span class="hljs-string">&apos;%char%&apos;</span>;
</code></pre>
<h4 id="t809.8.1.2  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [CONCAT]">9.8.1.2  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [CONCAT] <a href="#t809.8.1.2  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [CONCAT]"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">CONCAT</span>(last_name,<span class="hljs-string">&apos;_&apos;</span>,first_name) <span class="hljs-keyword">FROM</span> employees;
</code></pre>
<h4 id="t819.8.1.3  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [UPPER]">9.8.1.3  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [UPPER] <a href="#t819.8.1.3  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [UPPER]"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">UPPER</span>(<span class="hljs-string">&apos;zfpx&apos;</span>) <span class="hljs-keyword">FROM</span> employees;
</code></pre>
<h4 id="t829.8.1.4  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [LOWER]">9.8.1.4  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [LOWER] <a href="#t829.8.1.4  &#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32; [LOWER]"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">LOWER</span>(<span class="hljs-string">&apos;ZFPX&apos;</span>) <span class="hljs-keyword">FROM</span> employees;
</code></pre>
<h4 id="t839.8.1.5  &#x622A;&#x53D6;&#x5B57;&#x7B26;&#x4E32; [SUBSTR]">9.8.1.5  &#x622A;&#x53D6;&#x5B57;&#x7B26;&#x4E32; [SUBSTR] <a href="#t839.8.1.5  &#x622A;&#x53D6;&#x5B57;&#x7B26;&#x4E32; [SUBSTR]"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">SUBSTR</span>(<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-number">2</span>);<span class="hljs-comment">-- &#x622A;&#x53D6;&#x4ECE;&#x6307;&#x5B9A;&#x7D22;&#x5F15;&#x5904;&#x5F00;&#x59CB;&#x7684;&#x6240;&#x6709;&#x7684;&#x5B57;&#x7B26;</span>
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">SUBSTR</span>(<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>);<span class="hljs-comment">--&#x622A;&#x53D6;&#x4ECE;&#x6307;&#x5B9A;&#x7D22;&#x5F15;&#x5904;&#x5F00;&#x59CB;&#x7684;&#x6307;&#x5B9A;&#x6570;&#x91CF;&#x7684;&#x5B57;&#x7B26;</span>
</code></pre>
<h4 id="t849.8.1.6  &#x59D3;&#x540D;&#x7684;&#x9996;&#x5B57;&#x7B26;&#x5927;&#x5199;&#xFF0C;&#x5176;&#x5B83;&#x5B57;&#x7B26;&#x5C0F;&#x5199;&#x7136;&#x540E;&#x7528;_&#x62FC;&#x63A5;">9.8.1.6  &#x59D3;&#x540D;&#x7684;&#x9996;&#x5B57;&#x7B26;&#x5927;&#x5199;&#xFF0C;&#x5176;&#x5B83;&#x5B57;&#x7B26;&#x5C0F;&#x5199;&#x7136;&#x540E;&#x7528;_&#x62FC;&#x63A5; <a href="#t849.8.1.6  &#x59D3;&#x540D;&#x7684;&#x9996;&#x5B57;&#x7B26;&#x5927;&#x5199;&#xFF0C;&#x5176;&#x5B83;&#x5B57;&#x7B26;&#x5C0F;&#x5199;&#x7136;&#x540E;&#x7528;_&#x62FC;&#x63A5;"> # </a></h4>
<pre><code class="lang-sql"> <span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">CONCAT</span>(<span class="hljs-keyword">UPPER</span>(<span class="hljs-keyword">SUBSTR</span>(last_name,<span class="hljs-number">1</span>,<span class="hljs-number">1</span>)),<span class="hljs-string">&apos;_&apos;</span>,<span class="hljs-keyword">LOWER</span>(<span class="hljs-keyword">SUBSTR</span>(last_name,<span class="hljs-number">2</span>)));
</code></pre>
<h4 id="t859.8.1.7  &#x8FD4;&#x56DE;&#x5B50;&#x4E32;&#x5728;&#x539F;&#x59CB;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x8D77;&#x59CB;&#x7D22;&#x5F15;">9.8.1.7  &#x8FD4;&#x56DE;&#x5B50;&#x4E32;&#x5728;&#x539F;&#x59CB;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x8D77;&#x59CB;&#x7D22;&#x5F15; <a href="#t859.8.1.7  &#x8FD4;&#x56DE;&#x5B50;&#x4E32;&#x5728;&#x539F;&#x59CB;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x8D77;&#x59CB;&#x7D22;&#x5F15;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">INSTR</span>(<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-string">&apos;f&apos;</span>);
</code></pre>
<h4 id="t869.8.1.8  &#x53BB;&#x6389;&#x5DE6;&#x53F3;&#x7A7A;&#x683C;[TRIM]">9.8.1.8  &#x53BB;&#x6389;&#x5DE6;&#x53F3;&#x7A7A;&#x683C;[TRIM] <a href="#t869.8.1.8  &#x53BB;&#x6389;&#x5DE6;&#x53F3;&#x7A7A;&#x683C;[TRIM]"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">TRIM</span>(<span class="hljs-string">&apos;  zfpx  &apos;</span>);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">LTRIM</span>(<span class="hljs-string">&apos;  zfpx  &apos;</span>);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">RTRIM</span>(<span class="hljs-string">&apos;  zfpx  &apos;</span>);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">TRIM</span>(<span class="hljs-string">&apos;x&apos;</span> <span class="hljs-keyword">FROM</span> <span class="hljs-string">&apos;xxzfpxxx&apos;</span>);
</code></pre>
<h4 id="t879.8.1.9  &#x7528;&#x7A7A;&#x683C;&#x8865;&#x9F50;[LPAD]">9.8.1.9  &#x7528;&#x7A7A;&#x683C;&#x8865;&#x9F50;[LPAD] <a href="#t879.8.1.9  &#x7528;&#x7A7A;&#x683C;&#x8865;&#x9F50;[LPAD]"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">LPAD</span>(<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-number">10</span>,<span class="hljs-string">&apos;@&apos;</span>);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">LPAD</span>(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-number">8</span>,<span class="hljs-string">&apos;0&apos;</span>);
<span class="hljs-keyword">SELECT</span> RPAD(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-number">8</span>,<span class="hljs-string">&apos;0&apos;</span>);
</code></pre>
<h4 id="t889.8.1.10  &#x66FF;&#x6362;">9.8.1.10  &#x66FF;&#x6362; <a href="#t889.8.1.10  &#x66FF;&#x6362;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">REPLACE</span>(<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-string">&apos;f&apos;</span>,<span class="hljs-string">&apos;q&apos;</span>)
</code></pre>
<h4 id="t899.8.1.11  FORMAT">9.8.1.11  FORMAT <a href="#t899.8.1.11  FORMAT"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">FORMAT</span>(<span class="hljs-number">100000</span>,<span class="hljs-number">2</span>); 100,000.00
<span class="hljs-keyword">select</span> <span class="hljs-keyword">format</span>(<span class="hljs-number">100.31111</span>,<span class="hljs-number">2</span>) <span class="hljs-number">100.31</span>
<span class="hljs-keyword">select</span> <span class="hljs-keyword">format</span>(<span class="hljs-number">100.31111</span>,<span class="hljs-number">0</span>); 100
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">FORMAT</span>(<span class="hljs-number">423423234.65534453</span>,<span class="hljs-number">2</span>); 423,423,234.66
</code></pre>
<h4 id="t909.8.1.12 LEFT RIGHT">9.8.1.12 LEFT RIGHT <a href="#t909.8.1.12 LEFT RIGHT"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> <span class="hljs-keyword">left</span>(<span class="hljs-string">&apos;abcde12345&apos;</span>,<span class="hljs-number">5</span>);   //abcde
<span class="hljs-keyword">select</span> <span class="hljs-keyword">left</span>(<span class="hljs-string">&apos;abcde12345&apos;</span>,<span class="hljs-number">5</span>);   //12345
</code></pre>
<h3 id="t919.8.2 &#x6570;&#x5B66;&#x51FD;&#x6570;">9.8.2 &#x6570;&#x5B66;&#x51FD;&#x6570; <a href="#t919.8.2 &#x6570;&#x5B66;&#x51FD;&#x6570;"> # </a></h3>
<table>
<thead>
<tr>
<th style="text-align:left">&#x51FD;&#x6570;&#x540D;&#x79F0;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">CEIL</td>
<td style="text-align:left">&#x5411;&#x4E0A;&#x53D6;&#x6574;</td>
</tr>
<tr>
<td style="text-align:left">FLOOR</td>
<td style="text-align:left">&#x5411;&#x4E0B;&#x53D6;&#x6574;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">DIV</td>
<td style="text-align:left">&#x6574;&#x6570;&#x53D6;</td>
</tr>
<tr>
<td style="text-align:left">MOD</td>
<td style="text-align:left">&#x53D6;&#x4F59;(&#x53D6;&#x6A21;)</td>
</tr>
<tr>
<td style="text-align:left">POWER</td>
<td style="text-align:left">&#x5E42;&#x8FD0;&#x7B97;</td>
</tr>
<tr>
<td style="text-align:left">ROUND</td>
<td style="text-align:left">&#x56DB;&#x820D;&#x4E94;&#x5165;</td>
</tr>
<tr>
<td style="text-align:left">TRUNCATE</td>
<td style="text-align:left">&#x6570;&#x5B57;&#x622A;&#x53D6;</td>
</tr>
</tbody>
</table>
<h4 id="t929.8.2.1 &#x56DB;&#x820D;&#x4E94;&#x5165;">9.8.2.1 &#x56DB;&#x820D;&#x4E94;&#x5165; <a href="#t929.8.2.1 &#x56DB;&#x820D;&#x4E94;&#x5165;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">ROUND</span>(<span class="hljs-number">2.5</span>);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">ROUND</span>(<span class="hljs-number">2.555</span>,<span class="hljs-number">2</span>);
</code></pre>
<h4 id="t939.8.2.2 &#x5411;&#x4E0A;&#x53D6;&#x6574;">9.8.2.2 &#x5411;&#x4E0A;&#x53D6;&#x6574; <a href="#t939.8.2.2 &#x5411;&#x4E0A;&#x53D6;&#x6574;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">CEIL</span>(<span class="hljs-number">1.00</span>);
</code></pre>
<h4 id="t949.8.2.3 &#x5411;&#x4E0B;&#x53D6;&#x6574;">9.8.2.3 &#x5411;&#x4E0B;&#x53D6;&#x6574; <a href="#t949.8.2.3 &#x5411;&#x4E0B;&#x53D6;&#x6574;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">FLOOR</span>(<span class="hljs-number">1.00</span>);
</code></pre>
<h4 id="t959.8.2.4 &#x622A;&#x65AD;">9.8.2.4 &#x622A;&#x65AD; <a href="#t959.8.2.4 &#x622A;&#x65AD;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">TRUNCATE</span>(<span class="hljs-number">1.66</span>,<span class="hljs-number">1</span>);
</code></pre>
<h4 id="t969.8.2.5 &#x53D6;&#x4F59;">9.8.2.5 &#x53D6;&#x4F59; <a href="#t969.8.2.5 &#x53D6;&#x4F59;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">mod</span>(<span class="hljs-number">10</span>,<span class="hljs-number">3</span>);
</code></pre>
<h3 id="t979.8.3 &#x65E5;&#x671F;&#x51FD;&#x6570;">9.8.3 &#x65E5;&#x671F;&#x51FD;&#x6570; <a href="#t979.8.3 &#x65E5;&#x671F;&#x51FD;&#x6570;"> # </a></h3>
<table>
<thead>
<tr>
<th style="text-align:left">&#x51FD;&#x6570;&#x540D;&#x79F0;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">NOW</td>
<td style="text-align:left">&#x5F53;&#x524D;&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;</td>
</tr>
<tr>
<td style="text-align:left">CURDATE</td>
<td style="text-align:left">&#x5F53;&#x524D;&#x65E5;&#x671F;</td>
</tr>
<tr>
<td style="text-align:left">CURTIME</td>
<td style="text-align:left">&#x5F53;&#x524D;&#x65F6;&#x95F4;</td>
</tr>
<tr>
<td style="text-align:left">DATE_ADD</td>
<td style="text-align:left">&#x65E5;&#x671F;&#x53D8;&#x5316;</td>
</tr>
<tr>
<td style="text-align:left">DATEDIFF</td>
<td style="text-align:left">&#x8BA1;&#x7B97;&#x65E5;&#x671F;&#x5DEE;</td>
</tr>
<tr>
<td style="text-align:left">DATE_FORMAT</td>
<td style="text-align:left">&#x65E5;&#x671F;&#x683C;&#x5F0F;&#x5316;</td>
</tr>
</tbody>
</table>
<h4 id="t989.8.3.1 &#x8FD4;&#x56DE;&#x65E5;&#x671F;&#x65F6;&#x95F4;">9.8.3.1 &#x8FD4;&#x56DE;&#x65E5;&#x671F;&#x65F6;&#x95F4; <a href="#t989.8.3.1 &#x8FD4;&#x56DE;&#x65E5;&#x671F;&#x65F6;&#x95F4;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">NOW</span>():
</code></pre>
<h4 id="t999.8.3.2 &#x8FD4;&#x56DE;&#x65E5;&#x671F;">9.8.3.2 &#x8FD4;&#x56DE;&#x65E5;&#x671F; <a href="#t999.8.3.2 &#x8FD4;&#x56DE;&#x65E5;&#x671F;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">CURDATE</span>():
</code></pre>
<h4 id="t1009.8.3.3 &#x8FD4;&#x56DE;&#x65E5;&#x671F;">9.8.3.3 &#x8FD4;&#x56DE;&#x65E5;&#x671F; <a href="#t1009.8.3.3 &#x8FD4;&#x56DE;&#x65E5;&#x671F;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">CURTIME</span>():
</code></pre>
<h4 id="t1019.8.3.4 &#x8FD4;&#x56DE;&#x65E5;&#x671F;&#x4E2D;&#x6307;&#x5B9A;&#x7684;&#x90E8;&#x5206;">9.8.3.4 &#x8FD4;&#x56DE;&#x65E5;&#x671F;&#x4E2D;&#x6307;&#x5B9A;&#x7684;&#x90E8;&#x5206; <a href="#t1019.8.3.4 &#x8FD4;&#x56DE;&#x65E5;&#x671F;&#x4E2D;&#x6307;&#x5B9A;&#x7684;&#x90E8;&#x5206;"> # </a></h4>
<p>&#x5E74; &#x6708; &#x65E5; &#x5C0F;&#x65F6; &#x5206;&#x949F; &#x79D2;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">YEAR</span>(<span class="hljs-keyword">NOW</span>());
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">MONTH</span>(<span class="hljs-keyword">NOW</span>());
<span class="hljs-keyword">SELECT</span> MONTHNAME(<span class="hljs-keyword">NOW</span>());
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DAY</span>(<span class="hljs-keyword">NOW</span>());
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">HOUR</span>(<span class="hljs-keyword">NOW</span>());
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">MINUTE</span>(<span class="hljs-keyword">NOW</span>());
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">SECOND</span>(<span class="hljs-keyword">NOW</span>());
</code></pre>
<h4 id="t1029.8.3.5 str_to_date">9.8.3.5 str_to_date <a href="#t1029.8.3.5 str_to_date"> # </a></h4>
<p>&#x5C06;&#x65E5;&#x671F;&#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x6210;&#x6307;&#x5B9A;&#x683C;&#x5F0F;&#x7684;&#x65E5;&#x671F;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">STR_TO_DATE</span>(<span class="hljs-string">&apos;2018-09-09&apos;</span>,<span class="hljs-string">&apos;%Y-%m-%d&apos;</span>)
</code></pre>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5E8F;&#x53F7;</th>
<th style="text-align:left">&#x683C;&#x5F0F;&#x7B26;</th>
<th>&#x529F;&#x80FD;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">1</td>
<td style="text-align:left">%Y</td>
<td>4&#x4F4D;&#x7684;&#x5E74;&#x4EFD;</td>
</tr>
<tr>
<td style="text-align:left">2</td>
<td style="text-align:left">%y</td>
<td>2&#x4F4D;&#x7684;&#x5E74;&#x4EFD;</td>
</tr>
<tr>
<td style="text-align:left">3</td>
<td style="text-align:left">%m</td>
<td>&#x6708;&#x4EFD;(01,02)</td>
</tr>
<tr>
<td style="text-align:left">4</td>
<td style="text-align:left">%c</td>
<td>&#x6708;&#x4EFD;(1,2)</td>
</tr>
<tr>
<td style="text-align:left">5</td>
<td style="text-align:left">%d</td>
<td>&#x65E5;(01,02)</td>
</tr>
<tr>
<td style="text-align:left">6</td>
<td style="text-align:left">%H</td>
<td>&#x5C0F;&#x65F6;(24&#x5C0F;&#x65F6;&#x5236;)</td>
</tr>
<tr>
<td style="text-align:left">7</td>
<td style="text-align:left">%h</td>
<td>&#x5C0F;&#x65F6;(12&#x5C0F;&#x65F6;&#x5236;)</td>
</tr>
<tr>
<td style="text-align:left">8</td>
<td style="text-align:left">%i</td>
<td>&#x5206;&#x949F;(00,01)</td>
</tr>
<tr>
<td style="text-align:left">9</td>
<td style="text-align:left">%s</td>
<td>&#x79D2;(00,01)</td>
</tr>
</tbody>
</table>
<h4 id="t1039.8.3.6">9.8.3.6 <a href="#t1039.8.3.6"> # </a></h4>
<p>&#x67E5;&#x8BE2;&#x5165;&#x804C;&#x65E5;&#x671F;&#x4E3A;1984-8-4&#x7684;&#x5458;&#x5DE5;&#x4FE1;&#x606F;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> employees <span class="hljs-keyword">WHERE</span> hiredate = <span class="hljs-keyword">STR_TO_DATE</span>(<span class="hljs-string">&apos;12-30 1984&apos;</span>,<span class="hljs-string">&apos;%m-%d %Y&apos;</span>);
</code></pre>
<h4 id="t1049.8.3.7 DATE_FORMAT">9.8.3.7 DATE_FORMAT <a href="#t1049.8.3.7 DATE_FORMAT"> # </a></h4>
<p>&#x5C06;&#x65E5;&#x671F;&#x8F6C;&#x6362;&#x6210;&#x6307;&#x5B9A;&#x5B57;&#x7B26;&#x4E32;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DATE_FORMAT</span>(<span class="hljs-keyword">NOW</span>(),<span class="hljs-string">&apos;%Y&#x5E74;%m&#x6708;%d&#x65E5;&apos;</span>)
</code></pre>
<h4 id="t1059.8.3.8 DATE_ADD">9.8.3.8 DATE_ADD <a href="#t1059.8.3.8 DATE_ADD"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DATE_ADD</span>(<span class="hljs-keyword">NOW</span>(),<span class="hljs-built_in">INTERVAL</span> <span class="hljs-number">365</span> <span class="hljs-keyword">DAY</span>);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DATE_ADD</span>(<span class="hljs-keyword">NOW</span>(),<span class="hljs-built_in">INTERVAL</span> <span class="hljs-number">1</span> <span class="hljs-keyword">MONTH</span>);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DATE_ADD</span>(<span class="hljs-keyword">NOW</span>(),<span class="hljs-built_in">INTERVAL</span> <span class="hljs-number">1</span> <span class="hljs-keyword">YEAR</span>);
</code></pre>
<h4 id="t1069.8.3.9 DATEDIFF">9.8.3.9 DATEDIFF <a href="#t1069.8.3.9 DATEDIFF"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DATEDIFF</span>(<span class="hljs-string">&apos;2019-1-1&apos;</span>,<span class="hljs-keyword">NOW</span>());
</code></pre>
<h3 id="t1079.8.4 &#x5176;&#x5B83;&#x51FD;&#x6570;">9.8.4 &#x5176;&#x5B83;&#x51FD;&#x6570; <a href="#t1079.8.4 &#x5176;&#x5B83;&#x51FD;&#x6570;"> # </a></h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> CONNECTION_ID();
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DATABASE</span>();
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">VERSION</span>();
<span class="hljs-keyword">select</span> <span class="hljs-keyword">LAST_INSERT_ID</span>();
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">USER</span>();

<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">MD5</span>(<span class="hljs-string">&apos;123456&apos;</span>);//&#x6458;&#x8981;&#x7B97;&#x6CD5;
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">PASSWORD</span>(<span class="hljs-string">&apos;123456&apos;</span>);//&#x4FEE;&#x6539;&#x5F53;&#x524D;&#x7528;&#x6237;&#x7684;&#x5BC6;&#x7801;
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">User</span>,<span class="hljs-keyword">Password</span> <span class="hljs-keyword">from</span> mysql.user;
</code></pre>
<h3 id="t1089.9 &#x6D41;&#x7A0B;&#x63A7;&#x5236;&#x51FD;&#x6570;">9.9 &#x6D41;&#x7A0B;&#x63A7;&#x5236;&#x51FD;&#x6570; <a href="#t1089.9 &#x6D41;&#x7A0B;&#x63A7;&#x5236;&#x51FD;&#x6570;"> # </a></h3>
<h4 id="t1099.9.1 IF">9.9.1 IF <a href="#t1099.9.1 IF"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">IF</span>(<span class="hljs-number">1</span>&gt;<span class="hljs-number">0</span>,<span class="hljs-string">&apos;A&apos;</span>,<span class="hljs-string">&apos;B&apos;</span>);
</code></pre>
<h4 id="t1109.9.2 CASE&#x51FD;&#x6570;">9.9.2 CASE&#x51FD;&#x6570; <a href="#t1109.9.2 CASE&#x51FD;&#x6570;"> # </a></h4>
<pre><code class="lang-sql">CASE &#x8981;&#x5224;&#x65AD;&#x7684;&#x5B57;&#x6BB5;&#x548C;&#x8868;&#x8FBE;&#x5F0F;
WHEN &#x5E38;&#x91CF;1 then &#x8981;&#x663E;&#x793A;&#x7684;&#x503C;&#x6216;&#x8BED;&#x53E5;1
WHEN &#x5E38;&#x91CF;2 then &#x8981;&#x663E;&#x793A;&#x7684;&#x503C;&#x6216;&#x8BED;&#x53E5;2
ELSE &#x8981;&#x663E;&#x793A;&#x7684;&#x503C;
<span class="hljs-keyword">END</span>
</code></pre>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> 
<span class="hljs-keyword">CASE</span> 
<span class="hljs-keyword">WHEN</span> grade&lt;<span class="hljs-number">60</span> <span class="hljs-keyword">then</span> <span class="hljs-string">&apos;&#x4E0D;&#x53CA;&#x683C;&apos;</span>
<span class="hljs-keyword">WHEN</span> grade&gt;=<span class="hljs-number">60</span> <span class="hljs-keyword">then</span> <span class="hljs-string">&apos;&#x53CA;&#x683C;&apos;</span>
<span class="hljs-keyword">ELSE</span> <span class="hljs-string">&apos;&#x672A;&#x77E5;&apos;</span>
<span class="hljs-keyword">END</span>
<span class="hljs-keyword">FROM</span> score;
</code></pre>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> 
<span class="hljs-keyword">CASE</span> <span class="hljs-keyword">level</span>
<span class="hljs-keyword">WHEN</span> <span class="hljs-string">&apos;A&apos;</span> <span class="hljs-keyword">then</span> <span class="hljs-string">&apos;&#x4F18;&#x79C0;&apos;</span>
<span class="hljs-keyword">WHEN</span> <span class="hljs-string">&apos;B&apos;</span> <span class="hljs-keyword">then</span> <span class="hljs-string">&apos;&#x826F;&#x597D;&apos;</span>
<span class="hljs-keyword">ELSE</span> <span class="hljs-string">&apos;&#x672A;&#x77E5;&apos;</span>
<span class="hljs-keyword">END</span>
<span class="hljs-keyword">FROM</span> score;
</code></pre>
<h3 id="t1119.10 &#x7EC3;&#x4E60;">9.10 &#x7EC3;&#x4E60; <a href="#t1119.10 &#x7EC3;&#x4E60;"> # </a></h3>
<h4 id="t1129.10.1. &#x628A;&#x5B66;&#x751F;&#x8868;&#x4E2D;&#x7684;&#x90AE;&#x7BB1;&#x5730;&#x5740;&#x5168;&#x90E8;&#x7531;&#x5C0F;&#x5199;&#x6539;&#x4E3A;&#x5927;&#x5199;">9.10.1. &#x628A;&#x5B66;&#x751F;&#x8868;&#x4E2D;&#x7684;&#x90AE;&#x7BB1;&#x5730;&#x5740;&#x5168;&#x90E8;&#x7531;&#x5C0F;&#x5199;&#x6539;&#x4E3A;&#x5927;&#x5199; <a href="#t1129.10.1. &#x628A;&#x5B66;&#x751F;&#x8868;&#x4E2D;&#x7684;&#x90AE;&#x7BB1;&#x5730;&#x5740;&#x5168;&#x90E8;&#x7531;&#x5C0F;&#x5199;&#x6539;&#x4E3A;&#x5927;&#x5199;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">update</span> student <span class="hljs-keyword">set</span> email = <span class="hljs-keyword">UPPER</span>(email)
</code></pre>
<h4 id="t1139.10.2. &#x5B57;&#x6BB5;level&#x4E2D;&#x7684;&#x6570;&#x636E;&#x662F;  1-1&#x3001;1-2&#x3001;2-3&#x4E4B;&#x7C7B;&#x7684;&#xFF0C;&#x73B0;&#x5728;&#x8981;&#x6C42;&#x5148;&#x6309;&#x524D;&#x534A;&#x90E8;&#x5206;&#x5347;&#x5E8F;&#x6392;&#x5217;&#xFF0C;&#x518D;&#x6309;&#x540E;&#x534A;&#x90E8;&#x5206;&#x964D;&#x5E8F;&#x6392;&#x5217;">9.10.2. &#x5B57;&#x6BB5;level&#x4E2D;&#x7684;&#x6570;&#x636E;&#x662F;  1-1&#x3001;1-2&#x3001;2-3&#x4E4B;&#x7C7B;&#x7684;&#xFF0C;&#x73B0;&#x5728;&#x8981;&#x6C42;&#x5148;&#x6309;&#x524D;&#x534A;&#x90E8;&#x5206;&#x5347;&#x5E8F;&#x6392;&#x5217;&#xFF0C;&#x518D;&#x6309;&#x540E;&#x534A;&#x90E8;&#x5206;&#x964D;&#x5E8F;&#x6392;&#x5217; <a href="#t1139.10.2. &#x5B57;&#x6BB5;level&#x4E2D;&#x7684;&#x6570;&#x636E;&#x662F;  1-1&#x3001;1-2&#x3001;2-3&#x4E4B;&#x7C7B;&#x7684;&#xFF0C;&#x73B0;&#x5728;&#x8981;&#x6C42;&#x5148;&#x6309;&#x524D;&#x534A;&#x90E8;&#x5206;&#x5347;&#x5E8F;&#x6392;&#x5217;&#xFF0C;&#x518D;&#x6309;&#x540E;&#x534A;&#x90E8;&#x5206;&#x964D;&#x5E8F;&#x6392;&#x5217;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> <span class="hljs-keyword">SUBSTR</span>(<span class="hljs-keyword">level</span>,<span class="hljs-number">1</span>,<span class="hljs-number">1</span>),<span class="hljs-keyword">SUBSTR</span>(<span class="hljs-keyword">level</span>,<span class="hljs-number">3</span>,<span class="hljs-number">1</span>) <span class="hljs-keyword">from</span> <span class="hljs-keyword">user</span>
<span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> 
<span class="hljs-keyword">CONVERT</span>(<span class="hljs-keyword">SUBSTR</span>(<span class="hljs-keyword">level</span>,<span class="hljs-number">1</span>,<span class="hljs-number">1</span>),SIGNED) <span class="hljs-keyword">asc</span>,
<span class="hljs-keyword">CONVERT</span>(<span class="hljs-keyword">SUBSTR</span>(<span class="hljs-keyword">level</span>,<span class="hljs-number">3</span>,<span class="hljs-number">1</span>),SIGNED) <span class="hljs-keyword">desc</span>

<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">CAST</span>(<span class="hljs-string">&apos;123&apos;</span> <span class="hljs-keyword">AS</span> SIGNED);
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">CONVERT</span>(<span class="hljs-string">&apos;123&apos;</span>,SIGNED);
</code></pre>
<h4 id="t1149.10.3. &#x67E5;&#x8BE2;&#x5E74;&#x9F84;&#x8D85;&#x8FC7;18&#x5C81;&#x7684;&#x7537;&#x5B66;&#x751F;">9.10.3. &#x67E5;&#x8BE2;&#x5E74;&#x9F84;&#x8D85;&#x8FC7;18&#x5C81;&#x7684;&#x7537;&#x5B66;&#x751F; <a href="#t1149.10.3. &#x67E5;&#x8BE2;&#x5E74;&#x9F84;&#x8D85;&#x8FC7;18&#x5C81;&#x7684;&#x7537;&#x5B66;&#x751F;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> student
<span class="hljs-keyword">where</span> <span class="hljs-keyword">YEAR</span>(<span class="hljs-keyword">NOW</span>()) - <span class="hljs-keyword">YEAR</span>(birthday)&gt;=<span class="hljs-number">39</span>
</code></pre>
<h4 id="t1159.10.4. &#x67E5;&#x8BE2;&#x51FA;&#x751F;&#x6708;&#x4EFD;&#x662F;9&#x6708;&#x7684;&#x5C71;&#x4E1C;&#x7701;&#x540C;&#x5B66;">9.10.4. &#x67E5;&#x8BE2;&#x51FA;&#x751F;&#x6708;&#x4EFD;&#x662F;9&#x6708;&#x7684;&#x5C71;&#x4E1C;&#x7701;&#x540C;&#x5B66; <a href="#t1159.10.4. &#x67E5;&#x8BE2;&#x51FA;&#x751F;&#x6708;&#x4EFD;&#x662F;9&#x6708;&#x7684;&#x5C71;&#x4E1C;&#x7701;&#x540C;&#x5B66;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> student
<span class="hljs-keyword">where</span> <span class="hljs-keyword">MONTH</span>(birthday)&gt;=<span class="hljs-number">9</span>
</code></pre>
<h4 id="t1169.10.5. &#x67E5;&#x8BE2;&#x751F;&#x65E5;&#x662F;&#x4ECA;&#x5929;&#x7684;&#x5B66;&#x751F;&#x59D3;&#x540D;">9.10.5. &#x67E5;&#x8BE2;&#x751F;&#x65E5;&#x662F;&#x4ECA;&#x5929;&#x7684;&#x5B66;&#x751F;&#x59D3;&#x540D; <a href="#t1169.10.5. &#x67E5;&#x8BE2;&#x751F;&#x65E5;&#x662F;&#x4ECA;&#x5929;&#x7684;&#x5B66;&#x751F;&#x59D3;&#x540D;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> student
<span class="hljs-keyword">where</span> <span class="hljs-keyword">DAY</span>(<span class="hljs-keyword">NOW</span>()) = <span class="hljs-keyword">DAY</span>(birthday)
</code></pre>
<h4 id="t1179.10.6. &#x67E5;&#x8BE2;ID&#x4E3A;3&#x7684;&#x540C;&#x5B66;&#x90AE;&#x7BB1;&#x57DF;&#x540D;">9.10.6. &#x67E5;&#x8BE2;ID&#x4E3A;3&#x7684;&#x540C;&#x5B66;&#x90AE;&#x7BB1;&#x57DF;&#x540D; <a href="#t1179.10.6. &#x67E5;&#x8BE2;ID&#x4E3A;3&#x7684;&#x540C;&#x5B66;&#x90AE;&#x7BB1;&#x57DF;&#x540D;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> <span class="hljs-keyword">SUBSTR</span>(email <span class="hljs-keyword">FROM</span> <span class="hljs-keyword">INSTR</span>(email,<span class="hljs-string">&apos;@&apos;</span>)+<span class="hljs-number">1</span>) <span class="hljs-keyword">from</span> student
<span class="hljs-keyword">WHERE</span> <span class="hljs-keyword">ID</span> = <span class="hljs-number">3</span>;
</code></pre>
<h3 id="t1189.11 &#x81EA;&#x5B9A;&#x4E49;&#x51FD;&#x6570;">9.11 &#x81EA;&#x5B9A;&#x4E49;&#x51FD;&#x6570; <a href="#t1189.11 &#x81EA;&#x5B9A;&#x4E49;&#x51FD;&#x6570;"> # </a></h3>
<ul>
<li>&#x81EA;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#x662F;&#x5BF9;MySQL&#x7684;&#x6269;&#x5C55;&#xFF0C;&#x4F7F;&#x7528;&#x65B9;&#x5F0F;&#x548C;&#x5185;&#x7F6E;&#x51FD;&#x6570;&#x76F8;&#x540C;</li>
<li>&#x51FD;&#x6570;&#x5FC5;&#x987B;&#x8981;&#x6709;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;</li>
<li>&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x4EFB;&#x610F;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x8FD9;&#x4E9B;&#x7C7B;&#x578B;&#x7684;&#x53C2;&#x6570;</li>
<li>&#x51FD;&#x6570;&#x4F53;&#x7531;&#x5408;&#x6CD5;&#x7684;SQL&#x8BED;&#x53E5;&#x7EC4;&#x6210;</li>
<li>&#x51FD;&#x6570;&#x4F53;&#x53EF;&#x4EE5;&#x662F;&#x7B80;&#x5355;&#x7684;SELECT&#x8BED;&#x53E5;&#x6216;INSERT&#x8BED;&#x53E5;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x590D;&#x5408;&#x7ED3;&#x6784;&#x8981;&#x7528;BEGIN...END</li>
<li>&#x51FD;&#x6570;&#x4F53;&#x4E5F;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x58F0;&#x660E;&#xFF0C;&#x5FAA;&#x73AF;&#x548C;&#x6D41;&#x7A0B;&#x63A7;&#x5236;</li>
<li>&#x8FD4;&#x56DE;&#x503C;&#x53EA;&#x80FD;&#x6709;&#x4E00;&#x4E2A;</li>
</ul>
<h4 id="t1199.11.1 &#x8BED;&#x6CD5;">9.11.1 &#x8BED;&#x6CD5; <a href="#t1199.11.1 &#x8BED;&#x6CD5;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">FUNCTION</span> func_name <span class="hljs-keyword">RETURNS</span>  {<span class="hljs-keyword">String</span>|<span class="hljs-built_in">Integer</span>}
<span class="hljs-keyword">body</span>
</code></pre>
<h4 id="t1209.11.2 &#x5B9E;&#x4F8B;">9.11.2 &#x5B9E;&#x4F8B; <a href="#t1209.11.2 &#x5B9E;&#x4F8B;"> # </a></h4>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">FUNCTION</span> znow() <span class="hljs-keyword">RETURNS</span> <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">30</span>)
<span class="hljs-keyword">RETURN</span> <span class="hljs-keyword">DATE_FORMAT</span>(<span class="hljs-keyword">NOW</span>(),<span class="hljs-string">&apos;%Y&#x5E74;%m&#x6708;%d&#x65E5; %H&#x70B9;:%i&#x5206;%s&#x79D2;&apos;</span>);
</code></pre>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">FUNCTION</span> zadd(num1 <span class="hljs-built_in">INT</span>,num2 <span class="hljs-built_in">INT</span>) <span class="hljs-keyword">RETURNS</span> <span class="hljs-built_in">INT</span>
<span class="hljs-keyword">RETURN</span> num1+num2;
</code></pre>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> stu(<span class="hljs-keyword">id</span> <span class="hljs-built_in">int</span> PRIMARY <span class="hljs-keyword">KEY</span> AUTO_INCREMENT,<span class="hljs-keyword">name</span> <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">50</span>));
<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">FUNCTION</span> addUser(<span class="hljs-keyword">name</span> <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">50</span>)) <span class="hljs-keyword">RETURNS</span> <span class="hljs-built_in">INT</span>
<span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> stu(<span class="hljs-keyword">name</span>) <span class="hljs-keyword">VALUES</span>(<span class="hljs-keyword">name</span>);
  RETURN LAST_INSERT_ID();
<span class="hljs-keyword">END</span>

<span class="hljs-keyword">SELECT</span> addUser(<span class="hljs-string">&apos;zfpx&apos;</span>);
<span class="hljs-keyword">DROP</span> <span class="hljs-keyword">FUNCTION</span> addUser
</code></pre>
<h3 id="t1219.12 &#x6A21;&#x7CCA;&#x67E5;&#x8BE2;">9.12 &#x6A21;&#x7CCA;&#x67E5;&#x8BE2; <a href="#t1219.12 &#x6A21;&#x7CCA;&#x67E5;&#x8BE2;"> # </a></h3>
<p>&#x5C31;&#x662F;&#x67E5;&#x8BE2;&#x7684;&#x6761;&#x4EF6;&#x662F;&#x6A21;&#x7CCA;&#x7684;&#xFF0C;&#x4E0D;&#x662F;&#x7279;&#x522B;&#x660E;&#x786E;&#x7684;</p>
<h4 id="t1229.12.1 &#x901A;&#x914D;&#x7B26;">9.12.1 &#x901A;&#x914D;&#x7B26; <a href="#t1229.12.1 &#x901A;&#x914D;&#x7B26;"> # </a></h4>
<p>&#x4EE3;&#x66FF;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x771F;&#x6B63;&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x4E0E;LIKE &#x5173;&#x952E;&#x5B57;&#x4E00;&#x8D77;&#x4F7F;&#x7528;</p>
<p><img src="http://img.zhufengpeixun.cn/matchchar.png" alt="matchchar"></p>
<ul>
<li>&#x67E5;&#x8BE2;&#x59D3;&#x540D;&#x91CC;&#x5305;&#x542B;a&#x7684; %</li>
<li>&#x67E5;&#x770B;&#x59D3;&#x540D;&#x662F;&#x4EE5;a&#x5F00;&#x5934;&#x7684; %</li>
<li>&#x67E5;&#x770B;&#x59D3;&#x540D;&#x7B2C;&#x4E09;&#x4E2A;&#x5B57;&#x7B26;&#x662F;a&#x7684;  _</li>
</ul>
<h4 id="t1239.12.2  BETWEEN AND">9.12.2  BETWEEN AND <a href="#t1239.12.2  BETWEEN AND"> # </a></h4>
<p>&#x67E5;&#x8BE2;&#x67D0;&#x4E00;&#x5217;&#x5728;&#x6307;&#x5B9A;&#x7684;&#x89C4;&#x8303;&#x5185;&#x7684;&#x8BB0;&#x5F55;&#xFF0C;&#x5305;&#x62EC;&#x4E24;&#x4E2A;&#x8FB9;&#x754C;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> score <span class="hljs-keyword">where</span> grade <span class="hljs-keyword">between</span> <span class="hljs-number">80</span> <span class="hljs-keyword">and</span> <span class="hljs-number">100</span>
</code></pre>
<h4 id="t1249.12.3  IN">9.12.3  IN <a href="#t1249.12.3  IN"> # </a></h4>
<p>&#x67E5;&#x8BE2;&#x67D0;&#x4E00;&#x5217;&#x4E2D;&#x7684;&#x503C;&#x5728;&#x5217;&#x51FA;&#x7684;&#x5185;&#x5BB9;&#x5217;&#x8868;&#x4E2D;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> student <span class="hljs-keyword">where</span> city <span class="hljs-keyword">in</span> (<span class="hljs-string">&apos;&#x5317;&#x4EAC;&apos;</span>,<span class="hljs-string">&apos;&#x4E0A;&#x6D77;&apos;</span>,<span class="hljs-string">&apos;&#x5E7F;&#x4E1C;&apos;</span>)
</code></pre>
<h4 id="t1259.12.4 IS NUL">9.12.4 IS NUL <a href="#t1259.12.4 IS NUL"> # </a></h4>
<ul>
<li>&#x67E5;&#x8BE2;&#x6CA1;&#x6709;&#x90AE;&#x7BB1;&#x7684; IS NUL</li>
<li>&#x67E5;&#x8BE2;&#x6709;&#x90AE;&#x7BB1;&#x7684; IS NOT NULL</li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script><script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
